import java.util.Scanner;public class OnlineShoppingStore { { public static void main ( ( String [ ] [ ]
Fantastic news! We've Found the answer you've been seeking!
Question:
import java.util.Scanner;public class OnlineShoppingStore { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); int total =0; int quantity; System.out.println("Welcome to our online store!"); System.out.println("1: Banana, 0.99"); System.out.println("2: Apple, 1.99"); System.out.println("3: Orange, 0.79"); System.out.println("4: Grapes, 2.99"); System.out.println("Please select an item (1−4) or −1 to exit:"); int item = scanner.nextInt(); while (item !=−1){ System.out.println("Please enter the quantity of the selected item:"); quantity = scanner.nextInt(); switch (item){ case 1: System.out.println("You have selected Banana, price 0.99"); total += quantity *0.99; break; case 2: System.out.println("You have selected Apple, price 1.99"); total += quantity *1.99; break; case 3: System.out.println("You have selected Orange, price 0.79"); total += quantity *0.79; break; case 4: System.out.println("You have selected Grapes, price 2.99"); total += quantity *2.99; break; } System.out.println("1: Banana, 0.99"); System.out.println("2: Apple, 1.99"); System.out.println("3: Orange, 0.79"); System.out.println("4: Grapes, 2.99"); System.out.println("Please select an item (1−4) or −1 to exit:"); item = scanner.nextInt(); } System.out.println("Your total is "+ total); }}
Write an explanation for this java code
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Posted Date: