import java.util.List;

public class Chapter13Polymorphism {
    interface Command {
        String name();
        String execute();
    }

    record TextCommand(String name, String response) implements Command {
        @Override
        public String execute() {
            return response;
        }
    }

    static String process(String input, List<Command> commands) {
        for (Command command : commands) {
            if (command.name().equalsIgnoreCase(input)) {
                return command.execute();
            }
        }
        return "Unknown command.";
    }

    public static void main(String[] args) {
        List<Command> commands = List.of(
                new TextCommand("help", "Commands: help and tip."),
                new TextCommand("tip", "Program to small contracts."));
        System.out.println(process("tip", commands));
    }
}
