Title: JH1 Homework
Course: CPS 161: An Intro to Programming with Java - DL MM MASTER

JH1 Homework(50 points)

Create an Eclipse project named JH1_xxxxx where xxxxx is your NetID. For example: JH1_chasselb. Create the programs described below in this project. Fill in the required fields in the JH1_worksheet.txt file. Export your project file and upload it to blackboard as your work for this assignment. The worksheet file will be pasted into the blackboard comments section.

Get started early, and don't skip necessary video/lectures. If you find yourself stuck doing JH1, you should consider doing the practice work that would help prepare you for JH1:

Practice for JH1

Make sure you do your Class Participation (5 points)

primitive_variables problem (5 points):

Create a package named primitive_variables and copy the program named PrimitiveVariables from the "Java Fundamentals/Basics Simple Arithmetic" notes.

Change the variables "num1", "num2", and "answer" to be of type "double" (on my web, they are of type "int"). Also change the call to nextInt() to nextDouble().

Run the program with good input numbers and insert the results in the appropriate section of the JH1 worksheet. Lastly, try running your program with numbers that are not integers (i.e. something like "xyz") . Enter in a comment of what happened in the appropriate section in the JH1 Worksheet.

gas_mileage problem (5 points):

Create a package named gas_mileage and create a program that reads in from the keyboard the number of gallons of gas consumed by your car and the distance traveled. Your output is the miles per gallon for your vehicle.

Run your program with an input of 300 miles and 12.3 gallons of gas. Enter the results in the appropriate section in the JH1 Worksheet.

averager problem (10 points):

Create a package named averager and create a program called Average that reads 3 integers from the keyboard and prints their values as well as the average value of the 3 integers.

Run your program with inputs of 11, 15, and 24. Enter the results in the appropriate section in the JH1 Worksheet.

jar problem (10 points):

Create a package named jar and create a program called Jar that determines the value of the coins in a jar and prints the total in dollars and cents. Read integer values from the keyboard that represent the number of quarters, dimes, nickels, and pennies.

Some sample output from your program might be:

Enter in the number of Quarters in the Jar: 2
Enter in the number of Dimes in the Jar: 1
Enter in the number of Nickels in the Jar: 2
Enter in the number of Pennies in the Jar: 3

The jar contains 73 cents.

Enter some output from your program similar to the sample above into the appropriate section in the JH1 Worksheet.

make_change problem (15 points):

Create a package named make_change and create a program called MakeChange that prompts a user for the price of an item in dollars and cents.

The program then prompts the user for the money received in dollars and cents. The program then prints out the change that should be returned to the customer.

To simplify things assume that change is made in terms of dollars, quarters, dimes, nickels and pennies.

Some sample output might be:

Enter price dollars: 3
Enter price cents:   51

Enter money received dollars : 5
Enter money received cents: 0;

Change returned:
1 dollar(s)
1 quarter(s)
2 dime(s)
0 nickel(s)
4 pennies

HINTS:  It's best to keep your information in integers as pennies.
Integer divide and remainder operators (i.e. / %) are useful here.

For example:
int changeToReturn = 377;
The dollars to return are 377/100
and the remaining change to return after 3 dollars is:
377 % 100

Enter some output from your program similar to the sample above into the appropriate section in the JH1 Worksheet.

September 3, 2015 5:46 AM