package Views; import java.util.HashMap; import java.util.Map; import java.util.Scanner; import Views.Commands.Command; public class TextMenu { private Map commands; public TextMenu() { this.commands = new HashMap(); } public void addCommand(Command command) { this.commands.put(command.getKey(), command); } private void printMenu() { System.out.println("Menu:"); for (Command command : this.commands.values()) { String line = String.format("%4s: %s", command.getKey(), command.getDescription()); System.out.println(line); } } public void show() { var scanner = new Scanner(System.in); while (true) { this.printMenu(); System.out.println("Input the option: "); String key = scanner.nextLine(); Command command = this.commands.get(key); if (command == null) { System.out.println("Invalid option"); continue; } command.execute(); } } }