ahmed.adan.mohaHello, I have a project due soon for creating a self checkout machine in Java. The user inputs numbers that are added to a grand total and then taxed. My problem is at the end, when the user decides they bought enough things, they type -1 then the program goes straight to the calculation and if they type 0, the previous price is erased. I have the bare code of just adding the prices together but don't know how to erase the last number and stop the program to start the grand total calculation.
I'm supposed to use loops somewhere but only started learning about them. Any help would be appreciated. Thanks
---------------------(heres the barebones code but that shouldn't really matter, I just dont know what to type next)-----------------------
import java.util.Scanner; public class aaa { public static void main(String[] args) { System.out.println("Big Box Depot Self-Serve Checkout"); System.out.println(""); System.out.println("Hi. Welcome to the checkout. What's your name? "); System.out.println(""); Scanner input = new Scanner (System.in); String name = input.nextLine(); System.out.println(""); System.out.println("Okay, " + name + ", enter the price of each purchase in dollars and cents, and then push the ENTER key. For example, if item costs $5.99 enter 5.99"); System.out.println(""); System.out.println("If you make a mistake when you enter a price enter a zero for the next entry and the last price you entered will be subtracted from your running total."); System.out.println(""); System.out.println("When you've entered all of your prices, enter -1 to indicate that you've finished your entries. I’ll then calculate what your total owing is."); System.out.println(""); System.out.println("Enter a price for item #1: "); System.out.println(""); Scanner input2 = new Scanner (System.in); Double price1 = input2.nextDouble(); System.out.println("Enter a price for item #1: " + price1); System.out.println(""); System.out.println("That was $" + price1 + ". Your total is $" + price1 + "."); System.out.println(""); System.out.println(""); System.out.println("Enter a price for item #2: "); System.out.println(""); Scanner input3 = new Scanner (System.in); Double price2 = input3.nextDouble(); System.out.println("Enter a price for item #2: " + price2); if (price2 = 0) System.out.println(""); System.out.println("That was $" + price2 + ". Your total is $" + (price1 + price2) + "."); System.out.println("fin."); } }