So I need to do this with minimum code, and no if/else statement. With very basic and introductory java. For some reason, I'm having a hard time thinking through how to do this when I know the answer is so simple. Here is the assignment "Write a program that prompts the user to enter two double values, the first one the amount due on a bill and the second item the amount of money given to the clerk. The program must make change with dollar bills, quarters, dimes, nickels, and pennies. The clerk does not have any 50 cent pieces. For this program, we can assume the amount of money given is equal to or greater than the amount due. Sample out shown below. The output needs to be readable but does not have to match pecisely."
Here is the code I have so far.
// create link to scanner class Scanner input = new Scanner(System.in); // prompt user to input cost of purchase System.out.println("Enter the total cost of the purchase"); // store user input as totalCost double totalCost = input.nextDouble(); // prompt user to input amount of money they gave to clerk System.out.println("Enter the amount of money given to the clerk"); // store user input as amountGiven double amountGiven = input.nextDouble(); double totalChange = amountGiven - totalCost;
// create link to scanner class Scanner input = new Scanner(System.in); // prompt user to input cost of purchase System.out.println("Enter the total cost of the purchase"); // store user input as totalCost double totalCost = input.nextDouble(); // prompt user to input amount of money they gave to clerk System.out.println("Enter the amount of money given to the clerk"); // store user input as amountGiven double amountGiven = input.nextDouble(); double totalChange = amountGiven - totalCost;
Similar Threads
Recent Announcements
Continue the conversation
Join the Discord to ask follow-up questions and connect with the community
JC|HCL
Java Community | Help. Code. Learn.
We are a Community full of Java developers. Connect with other devs, get help, help others and do much more!