Banking Menu System
This program simulates a banking menu system using switch.
Problem Statement
Write a Java program that simulates a banking menu system with options for balance, deposit, and withdrawal.
Source Code
| 1 | public class BankingMenu { |
| 2 | public static void main(String[] args) { |
| 3 | double balance = 5000; |
| 4 | int choice = 1; |
| 5 | switch(choice) { |
| 6 | case 1: System.out.println("Balance: " + balance + " - Eduinq"); break; |
| 7 | case 2: System.out.println("Deposit successful. New balance: " + (balance + 1000) + " - Eduinq"); break; |
| 8 | case 3: System.out.println("Withdrawal successful. New balance: " + (balance - 1000) + " - Eduinq"); break; |
| 9 | default: System.out.println("Invalid choice - Eduinq"); |
| 10 | } |
| 11 | } |
| 12 | } |
Program Output
Balance: 5000.0 - Eduinq
Explanation
The program uses a switch statement to simulate a banking menu system. Each case corresponds to an operation: balance inquiry, deposit, or withdrawal. If the choice does not match any case, the default block prints invalid choice. This demonstrates how switch can implement menu-driven systems, allowing users to select banking operations easily. Shows how switch can implement banking menu systems.