From 386560346b29369ed3b918d86d6a8dc8bc027364 Mon Sep 17 00:00:00 2001 From: abazatte Date: Thu, 20 Jan 2022 08:51:39 +0100 Subject: [PATCH] first commit --- .idea/.gitignore | 8 ++++ .idea/misc.xml | 6 +++ .idea/modules.xml | 8 ++++ Test.iml | 11 +++++ out/production/Test/Main.class | Bin 0 -> 1999 bytes out/production/Test/Menue.class | Bin 0 -> 3789 bytes src/Main.java | 28 +++++++++++ src/Menue.java | 79 ++++++++++++++++++++++++++++++++ 8 files changed, 140 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 Test.iml create mode 100644 out/production/Test/Main.class create mode 100644 out/production/Test/Menue.class create mode 100644 src/Main.java create mode 100644 src/Menue.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -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/ diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..91063aa --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1a0e57f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Test.iml b/Test.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Test.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/Test/Main.class b/out/production/Test/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..b09436042a6edb582b0ba49143e3d2598e1f6234 GIT binary patch literal 1999 zcmcIlYgZdp6x|mn6Ncf@Ag|KWp|&+CNVN4)8(MACBG}MY!63!gCApA+d1PfKD1P%_ z_&4+e?V@Y>16=+lm;264AqcYk;>t?yoSSp@Id`9Z&;0S%!S4Wy*f!CDP6J&Q&Y@di za9i%mf-C*4!qbgyRgDC?=N#XO?g@0}@)ZLafpbgBZz&T7Iy2}M5Hd@!J`4RApuenE zRfB<-bNO-%*NPmsu-WpfkrViZQs9RzPc@4foEI39wVI=vk^R#T%CVozx~qJRJY?Yw z3=5czRgF=k-g!UaqSbS+88=TcX0LtrGg zep*Zx0)4uyNeh=@3-mTs!ByoDQ>KGuijy)aT9=?_{YbvP-{2@216{D>qd>50m2O2g9c`zZT~Xa3Sa(_Xwa94M+@d{nN?)mDPb-;B zlw(P2cQ2MhCXuBgH%1r>jTmB)dRz`#&8nJrbOAj&$E@a-9eWT25nW{?k!v{6ji)A_ z;d29DSXjo2z?Gxh<@me7jw+O;w^5Ufkejj^1JyRH>Vr z_OyM=zH19!lttfH&5|p_P=y9I1+JYq;%N;xQ0L`5+f`qKSRI%mwH+MNKo>_D=M8`F z(fXNoC)ep4FCbpQSbITH&t%O5SU`4gAKB@b7@0Z1MPMJ7X7(}lE8RQrF@GmH)xhvB ze)JFj5U?>c%o#Y}v{f9(Vw_wj%h6QP8MOs?nXBg_-22cI66bDQ3RUgj%|uCb)6 zt4G=Nn~HB4`uE4kR^l1sF+xvs?&w3U(^I2N{f6sVmOQK1_tN!)biK{>2z-R)1Lu)J z7K0eV7~eiNhT9TN9VVha(?pM%NEbDbnPZBH1KiOpwZZnsryrx!IIF%8!;K^%SR@ac s$v*VrGXi$vacq~d#PuTWC;WbiRXk6h*7@``JvUIJhsh^}EjSqe8#$5b761SM literal 0 HcmV?d00001 diff --git a/out/production/Test/Menue.class b/out/production/Test/Menue.class new file mode 100644 index 0000000000000000000000000000000000000000..c2e9121a97b5d5e5471854cdf221fb1b0621211d GIT binary patch literal 3789 zcmcIm>vt2!9lawNR+iSWSz|#+oG8R5vJ5y6XaPA+!PMA9c1UDQ2~Fr)9@~qhl`5?W z^pVo0Y15?d^pSV^NJ3tHgi}mQPJ8;PA9{NF=k#OR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iWspEdU0=l_OROFW*r29dFhtLV%`ucABiA$m_=L*G>- z*PA;sf5Hx{-@1JjcbxLugVtTTowWKh*D(Y%`h)E63Hl%S@jX5>wxQ0MX21^T@dSGU7aGiuvZt7LWmd8G3hr6OXD|QvKOBfc z1q$T3m4W(0KwTQ>qCbzzBkIaW9Hqs-xwM1thd;#V=_?q!h9fxwTc2OWvEfxbIL*%P z>v%}zl#l)uCugWZa`!4u{R7+9nt#WcJ%7Pt5nM*%3ch3&I9H_~u-e5-Ja`38V1Nk^ zvUI!HN>jHC_VMB|NyScJ#Alod$Y{n1OyDc{DyeSAL41uRjc`>OU&oWgR{3-z@)0Ht zj2bv;;2Q>~rf^B;Hp}VCFWXf@lAQQf6}*lmKb`do-9$LxKKf)IYp~y^k_^^rDn#+a zD*eBS<2u4I9U+k!RwnA8iEacvK;s=`We$Zv6AjP=zQwE*C{GRzdRBub$+i1MbOo$C zmHvOmxpiGFU#l?~cz}jFOcNam#Yi?{BsFne|1Avj6u!+Ms{V7#Txn#gT3Y=qdFj-8 zh`>-2EZwmXwAp|*@ie|eyzeRmzSZ+-Ji}J7Grz~yvv^L&dV;Z(*ZNefVR|UoP{Vsv zYdvUCj0dS%j+0hu52+mARef*<22 meD5TgpK|O)yo6VE>ovB1P12YB=R0_h^WyBkkKf~uxcPq}KCKe~ literal 0 HcmV?d00001 diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..c5311d3 --- /dev/null +++ b/src/Main.java @@ -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); + } + +} diff --git a/src/Menue.java b/src/Menue.java new file mode 100644 index 0000000..583e032 --- /dev/null +++ b/src/Menue.java @@ -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> commands; + private final HashMap 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 stringA) { + commands.replace("h", stringA); + } + + //Methode for putting your methode in the Menu + public void putMethode(String string, Consumer stringA, String text) { + commands.put(string, stringA); + description.put(string, text); + } +}