CS 117: Introduction to Computer Science
Change Maker

Assigned Wednesday, 1/8/02. Due Monday, 1/13/02, via HSP, by 8:30 AM. Hand in only your ChangeMaker.java file, and make sure your name and any other pertinent information (for example, citations of assistance you received from other people) is in the comment at the top of the file.

Create a class named ChangeMaker with a main method that asks the user for a purchase price and an amount tendered, and then displays the change in dollars, quarters, dimes, nickels, and pennies. The user should enter in both numbers in cents, for example 3450 for $34.50 and 70 for $0.70. Use InputBox for input and OutputBox for output. Display the output in the following format, as nearly as you can:



Purchase Price:  $34.50
Amount Tendered:  $40.00

Change:  $5.50
5 one-dollar bills
2 quarters

Your answer should be the natural one--the one that gives away as little small change as possible. You may assume that both the purchase price and the amount tendered are less than $100, and greater than $0.

Before stepping away from an assignment like this and moving on to other things, take a little time to think about what the assignment was for. Did the assignment increase your mastery of particular programming tools or language constructs? Did it illuminate some idea? Even a relatively dull assignment (making change is, I admit, not the most stimulating of computational tasks) is likely to have been assigned for a purpose, and you should make sure you understand what that purpose was.

Start early, have fun, and keep in touch.

Assignment from C. Thomas Wu, An Introduction to Object Oriented Programming With Java, McGraw-Hill, 2001.