Description
Objectives
- Read input from the keyboard of various types of data.
- Work with the modulus operator.
- Print output to the screen.
Motivation
If I tell you that I have 73 cents in American coins in my pocket and that I have the fewest number of coins possible, what combination of coins do I have? It turns out that I have 2 quarters (25 cents each), 2 dimes (10 cents each), 0 nickels (5 cents each), and 3 pennies (1 cent each).
- You can determine the number of quarters by taking the total divided by 25. In this case, that’s 73 divided by 25, which is 2. The rest is 73 modulo 25, which is 23. Use 23 for the next step.
- You can determine the number of dimes by taking the rest divided by 10. In this case, that’s 23 divided by 10, which is 2. The rest is 23 modulo 10, which is 3. Use 3 for the next step.
- You can determine the number of nickels by taking the rest and divided by 5. In this case, that’s 3 divided by 5, which is 0. The rest is 3 modulo 5, which is 3. Use 3 for the next step.
- The rest is pennies. In this case, that’s 3 pennies.
This very simple algorithm will always find the amount of change which equals a value using the smallest number of coins:
numberOfQuarters = total / quarterValue
total = total mod quarterValue
numberOfDimes = total / dimeValue
total = total mod dimeValue
numberOfNickels = total / nickelValue
total = total mod nickelValue
numberOfPennies = total / pennyValue
Instructions
Name your project FirstnameLastnameAssignment4
Have your program do the following.
- Make sure that the values of quarters, dimes, nickels, and pennies are stored as constants in your program. These values are 25, 10, 5, and 1 respectively.
- Greet the user with your name and what this program accomplishes.
- For example, “Welcome to Dr. Church’s Coin Change Calculator”
- Prompt the user for an amount of money in cents.
- Compute and display the number of quarters, dimes, nickels, and pennies. Make sure that each denomination is clearly labeled.
Your source code must include the following documentation:
- Your name
- The class (CS 2070) and the section number (on ground is 08, online is W1).
- The date on which you turned in the assignment.
- A short description of the software. Usually a sentence or two is sufficient.
Example Run
Not yet, but this should be enough to go on.
Turning it in.
To turn in your application, find the folder containing your entire project (not the folder with the “java” file), zip it up, and turn it in.