Put everything together. Build a menu system that reads a user's choice and responds with the right action.
import java.util.Scanner;
public class Menu {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("1. Check balance");
System.out.println("2. Deposit");
System.out.println("3. Withdraw");
System.out.println("4. Exit");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
switch (choice) {
case 1 -> System.out.println("Balance: ");
case 2 -> System.out.println("Deposit successful");
case 3 -> System.out.println("Withdrawal successful");
case 4 -> System.out.println("Goodbye");
default -> System.out.println("Invalid option");
}
}
}
This program uses Scanner to read input, a switch expression with arrows for clean branching, and a default case to handle unexpected input. Try extending it: add an option that prints help text, or validate that the input is a positive number before switching.