Montana Tech of The University of Montana
Computer Science & Software Engineering

CSCI 135
Fundamentals of Computer Science I
Fall 2017


The goal of this assignment is to use conditionals in Java. You will be using decision constructs (if statements and switch statements) in your code. Although we haven't talked about programming style guidelines yet, this is a good time to start practicing making your code readable. Be sure you pay attention to your header comment and other comments, your indentation and variable names, and careful use of whitespace and curly braces.

Part 1: If Statements
The first part of your assignment is to create a program that calculates to cost of mailing a package. You should name your program Given the weight of the package as a command line parameter, you need to calculate just how much it would cost to ship based on the following rules:

The cost of sending a package by an express delivery service is $15.00 for the first two pounds, and $5.00 for each pound or fraction thereof over two pounds. If the package weighs more then 70 pounds, a $15.00 excess weight surcharge is added to the cost. No package over 100 pounds will be accepted.

Write a program that accepts the weight of a package in pounds as a command line argument and computes the cost of mailing the package. Be sure to handle the case of overweight packages.

Some test input cases are shown below:

For the input "135" your program would print:

Package is over 100 pounds and cannot be shipped.
For the input "75" your program would print:

It will cost you $395.0 to ship your package.

For the input "60" your program would print:

It will cost you $305.0 to ship your package.

My program's output isn't quite the same as yours for the example input above. Is that okay? Not really. Learning to program involves a lot of attention to detail. You should strive to exactly match our example outputs. There will be plenty of opportunity for creativity in future assignments and extra-credit levels. The assignment page is the "contract", sticking to the exact program specification will make grading easier for the TA, and that is good for all involved!

Why do I only get one decimal place in my output when I really want two? We will look at how to format output later on in the semester. For now we can just live with some less than perfect output.

How do I declare a constant? When we get to methods and instance variable in classes, we will use the full declaration of "public static final ... ". For now, all you have to use is something like:

final double MAX_WEIGHT;
I accidently named my program Shipper or shipping or ... Is that okay? No. This will break our grading script. This is a surefire way to make your TA grumpy. Plus it is really easy to fix. Right click on the Java source file in the package explore, select Refactor -> Rename, and give it the correct name.

Part 2: Nested If Statements
Create a program that takes two command line arguments. Both numbers should be integers between 1 and 10, and they represent guesses on a lottery pick. Your program should generate two random numbers between 1 and 10, and compare them to the command line input. You are to use a nested if statement to determine whether the command line picks are winning numbers.

First, print out what the two randomly generated lottery numbers were, then what the command line arguments (the user's picks) were. Then, if there is no match, print out "Sorry, no match". If one number matches, print out "You matched one number! You win $100!!" Finally, if both number match print out "You matched both numbers! Congratualations! You win $1000!!"

Here is an example output given that no numbers matched:

The lottery numbers were 7 and 3.
Your picks were 2 and 8.
Sorry, no match.

Here is an example output where 1 number matched:

The lottery numbers were 4 and 2.
Your picks were 2 and 8.
You matched one number! You win $100!!

Here is an example output given that both numbers matched:

The lottery numbers were 2 and 6.
Your picks were 6 and 2.
You matched both numbers! Congratulations! You win $1000!!
How do I generate a random number between 1 and 10? Use the following line to get a random number in that range (pay attention to all the parentheses in this):
int lotteryNumber1 = (int) ((Math.random( )* 10) + 1);
Sometimes I get two random numbers that are the same. Is this OK?Yes, that can happen sometimes.

The random numbers that I get are not the same as in your examples. Is this OK?Yes, that is very likely to happen. In fact, it would be strange if your randomly generated numbers were the same as mine.

Part 3: Switch Statement
Create a program that determines the Chinese zodiac sign given a year of birth. The year of birth should be an integer. Use a switch statement in your program to determine which sign to output.

The rules for the Chinese zodiac signs are as follows: It is based on a 12 year cycle. If you were born in a year that is evenly divisible by 12, your sign is Monkey. If your year of birth, when divided by 12, has a remainder of 1, your sign is Rooster. Here is the entire list:

0: Monkey
1: Rooster
2: Dog
3: Pig
4: Rat
5: Ox
6: Tiger
7: Rabbit
8: Dragon
9: Snake
10: Horse
11: Sheep

So for example, for the input "1975" your program would print:

You were born in the year of the 

How do I find the remainder? Take a look back at our slides on expressions - the ones from 9/1, slide #7.

Grading Each of the three programs is worth 10 points each, for a total of 30 points. For each program, you will be graded according to the following criteria:

Grade ItemShippingLotteryZodiacPoints Earned
Program Compiles
Program Runs
Header Comment
Program Runs Correctly

Submission. Submit all three programs,, and via Moodle. Be sure each submitted source file has the required header with your name, and a description of the program. Also be sure to submit the .java source files and not the .class files!

Page last updated: August 15, 2018