Question
Modify the Java project to also return change of $5, $10 and $20. package convertreturnchangebills; import java.util.Scanner; public class ConvertReturnChangeBills { // 1) Declare Global
Modify the Java project to also return change of $5, $10 and $20.
package convertreturnchangebills;
import java.util.Scanner;
public class ConvertReturnChangeBills {
// 1) Declare Global variables to be used in project public static int DOLLARS = 100; public static int QUARTERS = 25; public static int DIMES = 10; public static int NICKELS = 5; public static int PENNIES = 1; // 2) Declare a Static Global object 'input' to be used in the Entire project public static Scanner input = new Scanner (System.in); public static void main(String[] args) { // 4) Call the methods to be used in this project from the main() method // 1) Call the printHeaders() method printHeaders(); // 2) Call calculateChangeReturned() method calculateChangeReturned(); // 3) Call the printFooters() Method printFooters(); } // End of the main() method // 5) Define and Code the Methods to be used Below the main() method //A) Define and code a Method to print the Headings of the project public static void printHeaders() { // 1) Print the Headings for the Project System.out.println("***************************************"); System.out.println(" ****** I will make Change for you. ********"); System.out.println("***************************************"); System.out.println(); } //B) Declare and code calculateChangeReturned() method public static void calculateChangeReturned() { // 1) Declare Local variables to be used in calculateChangeReturned() method int dollars, quarters, dimes, nickels, pennies; double changeReturned; // 2) Prompt the user to enter the amount for the change System.out.print("Enter in amount for the Change like 1.87: "); // 3) Read amount of Change from the Console and confirm the change changeReturned = input.nextDouble(); System.out.printf("Change to Return: = %.2f %n", changeReturned); // 4) Convert Change Returned to Pennies changeReturned = changeReturned * 100; // 5) Check if the Change Returned is >= than DOLLARS Constant 100 if (changeReturned >= DOLLARS) { // cast (int) to find number of Dollars dollars = (int) changeReturned / 100; System.out.println("Dollars = " + dollars); // Subtract the Dollars amount from change changeReturned = changeReturned - (dollars * 100); } // 6) Check if the Change Returned is >= than QUARTERS Constant 25 if (changeReturned >= QUARTERS) { // cast (int) to find number of Quarters quarters = (int)changeReturned / 25; System.out.printf("Quarters = %d %n", quarters); // Subtract the Quarters amount from change changeReturned = changeReturned - (quarters * 25); } // 7) Check if the Change Returned is >= than DIMES Constant 10 if (changeReturned >= DIMES) { // cast (int) to find number of Dimes dimes = (int) changeReturned / 10; System.out.printf("Dimes = %d %n", dimes); // Subtract the Dimes amount from change changeReturned = changeReturned - (dimes * 10); // 8) Check if the Change Returned is >= than NICKELS Constant 5 if (changeReturned >= NICKELS) { // cast (int) to find number of Nickels nickels = (int)changeReturned / 5; System.out.printf("Nickels = %d %n", nickels); // Subtract the Dimes amount from change changeReturned = changeReturned - (nickels * 5); } // 9) Check if the Change Returned is >= than PENNIES Constant 1 if (changeReturned >= PENNIES) { // cast (int) to find number of Pennies pennies = (int)changeReturned / 1; System.out.printf("Pennies = %d %n", pennies); // Subtract the Pennies amount from change changeReturned = changeReturned - (pennies * 1); } } //C) Define and code printFooters() method of the project
public static void printFooters() { System.out.println(); System.out.println("******** E n d O f J o b ************");
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
package convertreturnchangebills import javautilScanner public class ConvertReturnChangeBills public static int DOLLARS 100 public static int TWENTYDO...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