Menu-Driven Food Ordering System
This program simulates a food ordering system using switch.
Problem Statement
Write a Java program that prints food item based on menu choice.
Source Code
| 1 | public class FoodMenu { |
| 2 | public static void main(String[] args) { |
| 3 | int choice = 3; |
| 4 | switch(choice) { |
| 5 | case 1: System.out.println("Pizza - Eduinq"); break; |
| 6 | case 2: System.out.println("Burger - Eduinq"); break; |
| 7 | case 3: System.out.println("Pasta - Eduinq"); break; |
| 8 | case 4: System.out.println("Sandwich - Eduinq"); break; |
| 9 | default: System.out.println("Invalid choice - Eduinq"); |
| 10 | } |
| 11 | } |
| 12 | } |
Program Output
Pasta - Eduinq
Explanation
The program uses a switch statement to simulate a food ordering system. Each case corresponds to a menu item. If the choice matches, the program prints the selected food item. If no case matches, the default block prints invalid choice. This demonstrates how switch can implement menu-driven systems, allowing users to select options easily in applications like restaurant ordering systems. Shows how switch can implement menu-driven food ordering.