School Commit Init

This commit is contained in:
2024-08-31 12:07:21 +03:00
commit 0b130ee18c
2801 changed files with 4720552 additions and 0 deletions
@@ -0,0 +1,17 @@
package Views.Commands;
public abstract class Command {
private String key;
private String description;
public Command (String key, String description) {
this.key = key;
this.description = description;
}
public abstract void execute();
public String getKey() {
return this.key;
}
public String getDescription() {
return this.description;
}
}
@@ -0,0 +1,12 @@
package Views.Commands;
public class ExitCommand extends Command {
public ExitCommand(String key, String description) {
super(key, description);
}
@Override
public void execute() {
System.exit(0);
}
}
@@ -0,0 +1,16 @@
package Views.Commands;
import Controllers.Controller;
public class RunExampleCommand extends Command {
private Controller controller;
public RunExampleCommand(String key, String description, Controller controller) {
super(key, description);
this.controller = controller;
}
@Override
public void execute() {
this.controller.allSteps();
}
}
@@ -0,0 +1,38 @@
package Views;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import Views.Commands.Command;
public class TextMenu {
private Map<String, Command> commands;
public TextMenu() {
this.commands = new HashMap<String, Command>();
}
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();
}
}
}