CSE1020 Labtest 1A

Please read this part carefully

No collaboration is allowed during a labtest. Please refrain from speaking with other students during the test. If you have a question, please ask the teaching assistants or the instructor.

In your home directory you will find a copy of a solution to the ColourConvert problem from Lab 02. You may use pens/pencils and blank sheets of paper. No other aids are allowed.

You may use magic numbers instead of named constants for this test.

Your work will be evaluated based on its correctness and conformance to the style rules. Your code must compile to receive a passing grade.

Remember to save your work and submit your work at regular intervals during the test.

Test Problem

Write a program called MakeChange that reads one real number from the command line which represents an amount of change in dollars and cents. Your program should compute the number of loonies (one dollar coins), quarters, and pennies needed to make the amount of change using the most number of loonies and quarters as possible.

You might not know how to read real values from the command line; you can use the following line of code to read the amount of desired change from the command line:

double change = Double.parseDouble(args[0]);

Hint: Convert the amount of change into an integer number of cents first, and then compute the number of coins.

Your program should output the number of loonies, quarters, and pennies on separate lines as shown below (your program should generate the identical output):

java MakeChange 0.76
0 loonies
3 quarters
1 pennies

java MakeChange 2.56
2 loonies
2 quarters
6 pennies

java MakeChange 1.26
1 loonies
1 quarters
1 pennies

You may assume that the amount of change is always a "reasonable" amount (e.g., always positive or zero, not too large, has only 2 digits past the decimal).

Note that the "obvious" solution will often produce a result that is incorrect by 1 penny; this is acceptable for this test. The off-by-1-penny error occurs if you do not know how to round real numbers correctly in Java.

 

Submit

Submit your program using the command:

submit 1020 test01A MakeChange.java

You may leave when you are finished.