Monday, October 1, 2012

Java Exercise #9: Compute Change

This exercise is write a program that classifies given amount of money into smaller monetary units.

Exercise: Write a program that takes user input as a double value representing total in dollars and cents and outputs a report listing monteary equivalent in dollars, quarters, dimes, nickel and pennies.

Enter an amount in double (Eg: 11.56) : 11.56
 Your amount 11.56 consists of :
 11 dollars
 2 quarters
 0 dimes
 1 nickels
 1 pennies


Caution: One problem with the program is the loss of precision. Running the program for amount of 10.03, 10.03 * 100 to become 1002.9999999999. The program hence will output 10 dollars and 2 pennies. The program will need to re-written to take input in integers (say 1002 for 10.02 for instance).

Download Code: Compute Change

No comments:

Post a Comment