Untitled
unknown
plain_text
2 months ago
2.7 kB
1
Indexable
import java.util.Scanner; public class GrocerySystem extends GroceryStore { void processOrder() { Scanner input = new Scanner(System.in); while (choice != 6) { // Loop until checkout (6) is chosen choice = input.nextInt(); if (choice == 6) { // If checkout is chosen if (!hP) { // If no purchases were made System.out.println("No items purchased. Exiting..."); break; } System.out.print("Enter customer amount: P"); customerAmount = input.nextDouble(); // Correctly storing the entered amount System.out.println("Processing receipt..."); break; } int itemNumber = input.nextInt(); double price = 0; String itemName = ""; switch (itemNumber) { case 1: price = 50; itemName = "Dragon fruit"; break; case 2: price = 20; itemName = "Orange"; break; case 3: price = 30; itemName = "Banana"; break; case 4: price = 53; itemName = "Melona Ice Cream"; break; case 5: price = 75; itemName = "Tocino"; break; case 6: price = 75; itemName = "Coke 1.5"; break; case 7: price = 25; itemName = "Wilkins"; break; case 8: price = 40; itemName = "Patula"; break; case 9: price = 30; itemName = "Lettuce"; break; case 10: price = 170; itemName = "Chicken"; break; case 11: price = 300; itemName = "Beef"; break; default: System.out.println("Invalid selection."); continue; } int quantity = input.nextInt(); if (quantity > 0) { double totalCost = price * quantity; totalAmount += totalCost; hP = true; System.out.println(itemName + " x" + quantity + " - P" + totalCost); } else { System.out.println("Invalid quantity. Please enter a valid number."); } } } public void generateReceipt() { if (hP) { double change = customerAmount - totalAmount; System.out.println("--------------------------"); System.out.println("Total: P" + totalAmount); System.out.println("Amount Paid: P" + customerAmount); System.out.println("Change: P" + change); System.out.println("Thank you for shopping at PUREBROOZE GROCERY. Have a great day."); } } }
Editor is loading...
Leave a Comment