first commit
This commit is contained in:
parent
04adeb152c
commit
386560346b
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="true" project-jdk-name="15" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Test.iml" filepath="$PROJECT_DIR$/Test.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
11
Test.iml
Normal file
11
Test.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
BIN
out/production/Test/Main.class
Normal file
BIN
out/production/Test/Main.class
Normal file
Binary file not shown.
BIN
out/production/Test/Menue.class
Normal file
BIN
out/production/Test/Menue.class
Normal file
Binary file not shown.
28
src/Main.java
Normal file
28
src/Main.java
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
public class Main {
|
||||
public Main(String[] args) {
|
||||
Menue menue = new Menue();
|
||||
menue.putMethode("a", Main::addieren, "addiert zwei Zahlen");
|
||||
help(args);
|
||||
menue.replaceHelp(Main::help);
|
||||
menue.exitMessage("Bis zum nächsten mal!");
|
||||
menue.putCommands();
|
||||
}
|
||||
|
||||
private static void help(String[] args) {
|
||||
System.out.println("Functions: ");
|
||||
System.out.println(" (a) Addieren von zwei Werten");
|
||||
System.out.println(" (h) Hilfe. ");
|
||||
System.out.println(" (e) Exit. ");
|
||||
}
|
||||
|
||||
private static void addieren(String[] strings) {
|
||||
int a = 2 + 3;
|
||||
System.out.println("2 + 3 = " + a);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Main(args);
|
||||
}
|
||||
|
||||
}
|
79
src/Menue.java
Normal file
79
src/Menue.java
Normal file
@ -0,0 +1,79 @@
|
||||
import java.util.HashMap;
|
||||
import java.util.Scanner;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* This Class is a simple text menu where you can put your methode.
|
||||
*/
|
||||
public class Menue {
|
||||
//one HashMap is for Commands, the other is for the description.
|
||||
private final HashMap<String, Consumer<String[]>> commands;
|
||||
private final HashMap<String, String> description;
|
||||
private String exitMsg = "";
|
||||
private boolean exitMsgSet = false;
|
||||
|
||||
//default Constructor initialize both HashMaps and puts help and exit commands.
|
||||
public Menue() {
|
||||
commands = new HashMap<>();
|
||||
description = new HashMap<>();
|
||||
description.put("h", "help");
|
||||
description.put("e", "exit");
|
||||
commands.put("h", this::help);
|
||||
commands.put("e", this::exit);
|
||||
}
|
||||
|
||||
//while true loop for input (must be at the end of your code)
|
||||
public void putCommands() {
|
||||
while (true) {
|
||||
input();
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
//input Methode (used by only the class)
|
||||
private void input() {
|
||||
Scanner scan = new Scanner(System.in);
|
||||
System.out.print("$ ");
|
||||
String line = scan.nextLine();
|
||||
System.out.println("Input: " + line);
|
||||
|
||||
String[] args = new String[0];
|
||||
|
||||
if (commands.get(line) != null) {
|
||||
commands.get(line).accept(args);
|
||||
} else {
|
||||
System.err.println("INVALID INPUT");
|
||||
}
|
||||
}
|
||||
|
||||
//default help methode
|
||||
public void help(String[] args) {
|
||||
System.out.println("default help, for better feeling implement the Methode. ");
|
||||
System.out.println("Commands: " + description);
|
||||
}
|
||||
|
||||
//set exitMessage if u want
|
||||
public void exitMessage(String txt){
|
||||
exitMsg = txt;
|
||||
exitMsgSet = true;
|
||||
}
|
||||
|
||||
//exit methode
|
||||
public void exit(String[] args) {
|
||||
if (exitMsgSet){
|
||||
System.out.println(exitMsg);
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
//for replacing the scuffed help Methode
|
||||
public void replaceHelp(Consumer<String[]> stringA) {
|
||||
commands.replace("h", stringA);
|
||||
}
|
||||
|
||||
//Methode for putting your methode in the Menu
|
||||
public void putMethode(String string, Consumer<String[]> stringA, String text) {
|
||||
commands.put(string, stringA);
|
||||
description.put(string, text);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user