Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Grocery store program. Create a loop that can be stopped by the user by entry in

ID: 3647424 • Letter: G

Question

Grocery store program. Create a loop that can be stopped by the user by entry inside the loop(for example "enter a zero to quit",or "enter a q to quit"). Inside the loop create a menu system listing the items and their cost in your grocery store (must be real items for example apples - 10 cents per). You must have at least 10 items that have different prices.

Ask the user the quantity of the chosen item. Determine the cost and keep a running total to display after every entry. Once the user "fills their cart

Explanation / Answer

import java.util.Scanner; public class GroceryStore { public static void main(String[] args){ Scanner input = new Scanner(System.in); int product = 0; int apples = 0; int oranges = 0; int strawberries = 0; int bananas = 0; int potatoes = 0; int tomatoes = 0; int lemons = 0; int lettuce = 0; int cucumbers = 0; int celery = 0; int amount = 0; int total = celery + cucumbers + lettuce + lemons + tomatoes + potatoes + bananas + strawberries + oranges + apples; while (product != 99) { System.out.print("99- quit, 1- Apples, " + "2- Oranges, 3- Strawberries, " + "4- Bananas, 5- Potatoes, " + "6- Tomatoes, 7- Lemons, " + "8- Lettuce, 9- Cucumbers, " + "10- Celery "); product = input.nextInt(); if (product == 99) System.out.println("Your total is: " + total); else System.out.print("Enter amount: "); amount = input.nextInt(); switch (product){ case 1: apples = (int) (amount * 0.25); break; case 2: oranges = (int) (amount * 0.12); break; case 3: strawberries = (int) (amount * 0.30); break; case 4: bananas = (int) (amount * 0.10); break; case 5: potatoes = (int) (amount * 2.50); break; case 6: tomatoes = amount * 1; break; case 7: lemons = (int) (amount * 0.5); break; case 8: lettuce = (int) (amount * 0.30); break; case 9: cucumbers = (int) (amount * 0.18); break; case 10: celery = (int) (amount * 1.20); break; } } } }