Question
Write a program that displays change due back to a customer. The display should print out the number of quarters, dimes, nickels, and pennies. Test
Write a program that displays change due back to a customer. The display should print out the number of quarters, dimes, nickels, and pennies. Test your program using compile-time initialization of 97 pennies for the value to convert. Create a new project in NetBeans or any Java IDE, name it FirstName_LastName_A2 where FirstName is your first name and LastName is your last name. Submit your zipped project folder in Eagle Online Canvas for grading. To solve this problem, we can identify IPO and develop the Pseudocode.
1. Input: Total pennies to convert, in this case, we are using 97 pennies
2. Processing: To convert the given pennies to quarters, dimes, nickels, and pennies in this order.
3. Output: Display the result for each denomination.
4. Variables: pennies, quarters, dimes, nickels all are integer type
5. Constants: (See Note below) constants are not required, but might be helpful if you like flexible coding.
PENNY_TO_QTR= 25, PENNY_TO_DIME=10, PENNY_TO_NICKEL=5
Detailed Pseudocode:
1. Prompt user to enter total pennies
2. Read user input and store value into pennies variable
3. We already know the conversion for each denomination, just need to write it down.
a. Convert to quarters first, each quarter has 25 pennies, so we use quarters = pennies / 25 -- this calculation will give us total quarters. If you do create constant, you can use PENNY_TO_QTR instead of 25. (quarters = pennies / PENNY_TO_QTR)
b. We need to figure out the remaining pennies after converting to quarter, so that we can continue convert the remaining pennies to dimes. pennies = pennies % 25 -- use mod operator to calculate the remaining pennies dimes = pennies /10 -- get total dimes from the remaining pennies
c. We need to figure out the remaining pennies again, so that we can convert it to nickels; pennies = pennies % 10 -- use mod operator to calculate the remaining pennies nickels = pennies / 5 -- get total nickels from the remaining pennies
d. We just need to figure out the final remaining pennies pennies = pennies % 5 this will give us the final pennies.
4. Display quarters, dimes, nickels, and pennies.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started