COSC 1046, Assignment 1

Due date: Friday, Week 3, 8 am (in lockerette)

Writing a change helper program in Java

Write a program called ChangeHelper that helps a cashier give change to a customer. First write a pseudo-code version of the algorithm. The program has two inputs: the amount due (e.g., 3.28) and the amount received from the customer (e.g 5.00). Use double variables for them. Assume that the amount received from the customer is equal to or greater than the amount due.

Using the pseudo-code algorithm and the CircleCalculator and CircleCalculatorRunner classes in Chapter 3 of the text book as a guide, write a Java class called ChangeHelper and a corresponding runner class called ChangeHelperRunner containing a main method that constructs a ChangeHelper object and sends readInput, doCalculations and displayResults messages to it.

The program should output the minimum number of dollars, quarters, dimes, nickels and cents the customer should receive in return. A sample output should look exactly like this:

 Enter the amount due: 3.28
 Enter the amount received by customer: 5.00
 Give the customer the following change
 dollars: 1
 quarters: 2
 dimes: 2
 nickels: 0
 pennies: 2
Hint: First convert the two double amounts to total pennies (multiply by 100 and round to nearest long integer using Math.round, and typecast to an int using (int)). Then subtract to get the total pennies change. Then use / and % a few times to extract the numbers for each type of coin.

Marking scheme

Pseudo-code algorithm [5 MARKS], Java program classes [20 MARKS].

What to submit

Submit a report consisting of a title page (name, section, student number), a page containing your pseudo-code algorithm and pages containing printouts for the files ChangeHelper.java and ChangeHelperRunner.java. Staple sheets together and submit with a disk containing your java and class files in an envelope available from the department. Make two copies of your report. Keep one for yourself and submit the other.

Note on assignment marking

Your programs will be marked for correctness but it is also very important to use good style and organization (see style guide on course web page). For this assignment, the markers will make comments about your style. For future assignments style will be marked.

Note: Assignment 1 is shorter than remaining assignments to give you time to adapt to the Java and lab environments.