public class Store {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double price;
double total=0;
int item=1;
while(true){
System.out.print("Item " + item + " price: ");
price = sc.nextDouble();
total=total+price;
item=item+1;
if(price==0){
break;
}
}
System.out.printf("Total: $%.2f \n", total);
System.out.print("Enter your payment in dollars:");
double payment = sc.nextDouble();
double change = payment - total;
System.out.printf("Your change: $%.2f \n", change);
}
}
A storeowner asks you to write a program for use in the checkout process.
The program should:
・ Prompt the user to enter the cost of the first item.
・ Continue to prompt for additional items, until the user enters 0.
・ Display the total.
・ Prompt for the dollar amount the customer submits as payment.
・ Display the change due.
Should look like Sample output Below:
Enter the cost of your first item in dollars, or 0 to quit: 4
Enter the cost of your next item in dollars, or 0 to quit: 5
Enter the cost of your next item in dollars, or 0 to quit: 0
Your total is $ 9.00
Enter your payment in dollars: 12
Your change is $ 3.00