Online Shopping Menu

This program simulates an online shopping menu using switch.

Problem Statement

Write a Java program that simulates an online shopping menu with options for electronics, clothing, and groceries.

Source Code

1 public class ShoppingMenu {
2 public static void main(String[] args) {
3 int choice = 1;
4 switch(choice) {
5 case 1: System.out.println("Electronics section - Eduinq"); break;
6 case 2: System.out.println("Clothing section - Eduinq"); break;
7 case 3: System.out.println("Groceries section - Eduinq"); break;
8 default: System.out.println("Invalid choice - Eduinq");
9 }
10 }
11 }

Program Output

Electronics section - Eduinq

Explanation

The program uses a switch statement to simulate an online shopping menu. Each case corresponds to a shopping category. If the choice matches, the program prints the selected category. If no case matches, the default block prints invalid choice. This demonstrates how switch can implement menu-driven systems, allowing users to select shopping categories easily in e-commerce applications. Shows how switch can simulate online shopping menus.

Quick Links to Explore