Question: This was one of the problems from the first assignment. Correct Change: Write a program to assist a cashier with determining correct change. Create a
This was one of the problems from the first assignment. Correct Change: Write a program to assist a cashier with determining correct change.
Create a Change Class.
Create 4 integer instance variable, one for quarters, dimes, nickels, pennies.
Create a constructor that does not have any parameters and sets each of the instance variables to 0.
Create 4 integer constant variables. One for quarters (ie. private static final int QUARTER_VALUE = 25. Do the same thing for dimes, nickels, and pennies.
Create a calculateQuarters method. This method should accept a single integer (amount) to serves as the argument as used as input to the method. Calculate the number of quarters by dividing amount by the value of quarters and assign it to the quarters instance variable. Use the QUARTER_VALUE variable in your calculations see page 137. Using modulus (see page 138-139 of the text) determine the remainder. The remainder should be returned to the calling program.
Create 3 more methods like the calculateQuarters for dimes, nickels and pennies.
Create 4 get methods. One to return the number of quarters, one for dimes, one for nickels, and one for pennies.
Create a ChangeTester
Import Scanner.
Create a Scanner object.
Prompt the user to enter the amount.
Create an integer variable named change and using Scanner get the input from the user.
Create an object of type Change.
Create an integer variable called remainder and set it to 0.
Call the calculateQuarters method and put the return value in the variable called remainder. Example: remainer = myObject.calculateQuaters(change);
Call the calculateDimes method and put the return value in the variable called remainder. In this case, when you call calculateDimes use remainder as the parameter.
Repeat sept p for nickels and pennies.
Call and print getQuarters(), getDimes(), getNickels(), and getPennies(). When printing identify each number printed. Example: Quarters: 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
