Untitled
unknown
plain_text
8 months ago
1.6 kB
3
Indexable
import java.util.Scanner;
public class GrocerySystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double total = 0;
System.out.println("Welcome to the Grocery Store");
while (true) {
System.out.println("1. Buy Apple (20 Pesos)");
System.out.println("2. Buy Bear brand(14 Pesos)");
System.out.println("3. Buy Gardenia bread (150 Pesos)");
System.out.println("4. Buy Melona (50 Pesos)");
System.out.println("5. Checkout");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
if (choice == 1) {
total += 20;
System.out.println("Apple added to cart.");
}
else if (choice == 2) {
total += 14;
System.out.println(" Bear brand added to cart.");
}
else if (choice == 3) {
total += 150;
System.out.println("Gardenia bread added to cart.");
}
else if (choice == 4) {
total += 50;
System.out.println("Melona added to cart.");
}
else if (choice == 5) {
System.out.println("Total amount: Pesos" + total);
System.out.println("Thank you for shopping!");
break;
}
else {
System.out.println("Invalid choice. Try again.");
}
}
scanner.close();
}
}
Editor is loading...
Leave a Comment