From a5a39dc07e152558fb6fba517434a45c53a693a1 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 8 Oct 2020 17:21:26 -0700 Subject: [PATCH 01/10] thread in main --- src/main/java/org/jointheleague/discord_bot_example/Bot.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jointheleague/discord_bot_example/Bot.java b/src/main/java/org/jointheleague/discord_bot_example/Bot.java index ce92bc19..4eec3fe0 100644 --- a/src/main/java/org/jointheleague/discord_bot_example/Bot.java +++ b/src/main/java/org/jointheleague/discord_bot_example/Bot.java @@ -22,7 +22,7 @@ public class Bot { private String channelName; DiscordApi api; _HelpListener helpListener; - + public Bot(String token, String channelName) { this.token = token; this.channelName = channelName; From 97588542f97c14f8070159d620118cc0c9de6276 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 8 Oct 2020 17:27:23 -0700 Subject: [PATCH 02/10] check --- src/main/java/org/jointheleague/discord_bot_example/Bot.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jointheleague/discord_bot_example/Bot.java b/src/main/java/org/jointheleague/discord_bot_example/Bot.java index 4eec3fe0..2bcaaafe 100644 --- a/src/main/java/org/jointheleague/discord_bot_example/Bot.java +++ b/src/main/java/org/jointheleague/discord_bot_example/Bot.java @@ -22,13 +22,14 @@ public class Bot { private String channelName; DiscordApi api; _HelpListener helpListener; - + public Bot(String token, String channelName) { this.token = token; this.channelName = channelName; helpListener = new _HelpListener(channelName); } + public void connect(boolean printInvite) { api = new DiscordApiBuilder().setToken(token).login().join(); From 139ed97e4d39028ca083240fae217d0d41066366 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 29 Apr 2021 17:05:45 -0700 Subject: [PATCH 03/10] Finished First Part --- .../jointheleague/modules/LisztsLists.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/main/java/org/jointheleague/modules/LisztsLists.java diff --git a/src/main/java/org/jointheleague/modules/LisztsLists.java b/src/main/java/org/jointheleague/modules/LisztsLists.java new file mode 100644 index 00000000..025ef47c --- /dev/null +++ b/src/main/java/org/jointheleague/modules/LisztsLists.java @@ -0,0 +1,52 @@ +package org.jointheleague.modules; + +import java.util.Random; + +import org.javacord.api.event.message.MessageCreateEvent; + +import net.aksingh.owmjapis.api.APIException; + +public class LisztsLists extends CustomMessageCreateListener { + private static final String command = "!lisztlist"; + public LisztsLists(String channelName) { + super(channelName); + // TODO Auto-generated constructor stub + } + + @Override + public void handle(MessageCreateEvent event) throws APIException { + // TODO Auto-generated method stub + if(event.getMessageContent().contains("!lisztlist")) { + int r = new Random().nextInt(7); + if(r == 0) { + event.getChannel().sendMessage("Liszt’s father was strict about him practicing with a metronome, which might be one reason Liszt was well-known for his ability to keep absolute tempo."); + } + if(r == 1) { + event.getChannel().sendMessage("In addition to his father knowing the Classical greats, Liszt himself studied with Carl Czerny as a boy. Carl Czerny was one of Beethoven’s best students, and was a renowned piano teacher."); + } + if(r == 2) { + event.getChannel().sendMessage("Liszt was Elvis before Elvis was Elvis. They called it “Lisztomania” – women would faint and go into a frenzy when he performed, so much so that local doctors thought it was an epidemic of mental illness."); + } + if(r == 3) { + event.getChannel().sendMessage("Liszt’s fame allowed him to fill concert halls with his solo performances, and he elevated the piano as a solo instrument in the concert hall as well."); + } + if(r == 4) { + event.getChannel().sendMessage("Because of his motivation, drive and hard work, Liszt built up an unparalleled technical prowess at the piano. "); + } + if(r == 5) { + event.getChannel().sendMessage("Liszt was such an intense piano player – loud enough to fill a recital hall on his own – that he would break piano strings while playing."); + } + if(r == 6) { + event.getChannel().sendMessage("In addition to being virtuosic and loud, Liszt created an entire genre of music – the symphonic poem."); + } + if(r == 7) { + event.getChannel().sendMessage("Liszt was known for being generous to friends and family."); + } + + + } + + + } + +} From 98004cb4aabce536eb2712f6c2582c6e8b14d6ab Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 29 Apr 2021 17:12:53 -0700 Subject: [PATCH 04/10] # WARNING: head commit changed in the meantime update --- src/main/java/org/jointheleague/discord_bot_example/Bot.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/jointheleague/discord_bot_example/Bot.java b/src/main/java/org/jointheleague/discord_bot_example/Bot.java index 2bcaaafe..3aa61ad1 100644 --- a/src/main/java/org/jointheleague/discord_bot_example/Bot.java +++ b/src/main/java/org/jointheleague/discord_bot_example/Bot.java @@ -134,6 +134,7 @@ public void connect(boolean printInvite) { api.addMessageCreateListener(new RandomCase(channelName)); api.addMessageCreateListener(new GetTime(channelName)); api.addMessageCreateListener(new ScreenCapture(channelName)); + api.addMessageCreateListener(new LisztsLists(channelName)); } } From 1d46e9be90f4c48e0f3a7c5df5ce4db14cda441d Mon Sep 17 00:00:00 2001 From: league Date: Thu, 10 Jun 2021 18:31:14 -0700 Subject: [PATCH 05/10] working on logic of equation solver --- src/main/java/EquationSolver.java | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/main/java/EquationSolver.java diff --git a/src/main/java/EquationSolver.java b/src/main/java/EquationSolver.java new file mode 100644 index 00000000..64721e6e --- /dev/null +++ b/src/main/java/EquationSolver.java @@ -0,0 +1,52 @@ +import java.util.ArrayList; + +public class EquationSolver { + static String eq = "1+22-333*4444/55555"; + static String num = ""; + static ArrayList hold; + + public static void main(String[] args) { + hold = new ArrayList(); + for (int i = 0; i < eq.length(); i++) { + if(eq.charAt(eq.length()-1)=='+' ||eq.charAt(eq.length()-1)=='-'||eq.charAt(eq.length()-1)=='/'||eq.charAt(eq.length()-1)=='*'){ + System.out.println("Not A Valid Equation"); + System.exit(0); + } + + if (Character.isDigit(eq.charAt(i))) { + num += "" + eq.charAt(i); + + } else { + //int add = Integer.parseInt(num); + hold.add(num); + num = ""; + + + } + + if (eq.charAt(i) == '+') { + hold.add("+"); + } + if (eq.charAt(i) == '-') { + hold.add("-"); + } + if (eq.charAt(i) == '*') { + hold.add("*"); + } + if (eq.charAt(i) == '/') { + hold.add("/"); + } +/* 5+6*7-8/2 + * 5+42-8/2 + * 5+42-4 + * 47-4 + * 43 + */ + } + hold.add(num); + num = ""; + + System.out.println(hold); + } + +} From da7d92014f545450659bdcc464f34e0dfe6426e0 Mon Sep 17 00:00:00 2001 From: league Date: Thu, 17 Jun 2021 18:05:05 -0700 Subject: [PATCH 06/10] finished the equations --- src/main/java/EquationSolver.java | 71 +++++++--- .../discord_bot_example/Bot.java | 9 +- .../discord_bot_example/Launcher.java | 1 + .../jointheleague/modules/EquatonSolver.java | 122 ++++++++++++++++++ src/main/resources/config.json | 4 +- 5 files changed, 187 insertions(+), 20 deletions(-) create mode 100644 src/main/java/org/jointheleague/modules/EquatonSolver.java diff --git a/src/main/java/EquationSolver.java b/src/main/java/EquationSolver.java index 64721e6e..c4aba974 100644 --- a/src/main/java/EquationSolver.java +++ b/src/main/java/EquationSolver.java @@ -1,29 +1,29 @@ import java.util.ArrayList; public class EquationSolver { - static String eq = "1+22-333*4444/55555"; + static String eq = "1/3"; static String num = ""; static ArrayList hold; public static void main(String[] args) { hold = new ArrayList(); for (int i = 0; i < eq.length(); i++) { - if(eq.charAt(eq.length()-1)=='+' ||eq.charAt(eq.length()-1)=='-'||eq.charAt(eq.length()-1)=='/'||eq.charAt(eq.length()-1)=='*'){ + if (eq.charAt(eq.length() - 1) == '+' || eq.charAt(eq.length() - 1) == '-' + || eq.charAt(eq.length() - 1) == '/' || eq.charAt(eq.length() - 1) == '*') { System.out.println("Not A Valid Equation"); System.exit(0); - } - + } + if (Character.isDigit(eq.charAt(i))) { num += "" + eq.charAt(i); } else { - //int add = Integer.parseInt(num); + // int add = Integer.parseInt(num); hold.add(num); num = ""; - - + } - + if (eq.charAt(i) == '+') { hold.add("+"); } @@ -36,17 +36,58 @@ public static void main(String[] args) { if (eq.charAt(i) == '/') { hold.add("/"); } -/* 5+6*7-8/2 - * 5+42-8/2 - * 5+42-4 - * 47-4 - * 43 - */ + /* + * 5+6*7-8/2 5+42-8/2 5+42-4 47-4 43 + */ } hold.add(num); num = ""; + + + boolean done = false; + String[] symbols = { "*", "/", "+", "-" }; + int currentIndex = 0; + String currentSym = symbols[currentIndex]; + while (!done) { + boolean found = false; - System.out.println(hold); + for (int i = 0; i < hold.size(); i++) { + if (hold.get(i).equals(currentSym)) { + double fVal = Double.parseDouble(hold.get(i - 1)); + double sVal = Double.parseDouble(hold.get(i + 1)); + double solution = 0; + if (hold.get(i).equals("*")) { + solution = fVal * sVal; + } + if (hold.get(i).equals("/")) { + solution = fVal / sVal; + } + if (hold.get(i).equals("+")) { + solution = fVal + sVal; + } + if (hold.get(i).equals("-")) { + solution = fVal - sVal; + } + hold.remove(i - 1); + hold.remove(i - 1); + String ans = "" + solution; + hold.set(i - 1, ans); + found = true; + break; + } + } + if (!found) { + currentIndex++; + + if (currentIndex >= symbols.length) { + done = true; + } else { + + currentSym = symbols[currentIndex]; + } + } + } + } } diff --git a/src/main/java/org/jointheleague/discord_bot_example/Bot.java b/src/main/java/org/jointheleague/discord_bot_example/Bot.java index 88ed18d2..4f3fdb4a 100644 --- a/src/main/java/org/jointheleague/discord_bot_example/Bot.java +++ b/src/main/java/org/jointheleague/discord_bot_example/Bot.java @@ -48,9 +48,9 @@ public void connect(boolean printInvite) { api.addMessageCreateListener(dl); helpListener.addHelpEmbed(dl.getHelpEmbed()); - CurrencyConverter cc = new CurrencyConverter(channelName); - api.addMessageCreateListener(cc); - helpListener.addHelpEmbed(cc.getHelpEmbed()); +// CurrencyConverter cc = new CurrencyConverter(channelName); +// api.addMessageCreateListener(cc); +// helpListener.addHelpEmbed(cc.getHelpEmbed()); ToDoList list = new ToDoList(channelName); api.addMessageCreateListener(list); @@ -128,6 +128,9 @@ public void connect(boolean printInvite) { DiscordZoomAccess dza = new DiscordZoomAccess(channelName); api.addMessageCreateListener(dza); helpListener.addHelpEmbed(dza.getHelpEmbed()); + + EquatonSolver eq = new EquatonSolver(channelName); + api.addMessageCreateListener(eq); CovidCaseGetter covid = new CovidCaseGetter(channelName); api.addMessageCreateListener(covid); diff --git a/src/main/java/org/jointheleague/discord_bot_example/Launcher.java b/src/main/java/org/jointheleague/discord_bot_example/Launcher.java index fdbfb858..fabc5d46 100644 --- a/src/main/java/org/jointheleague/discord_bot_example/Launcher.java +++ b/src/main/java/org/jointheleague/discord_bot_example/Launcher.java @@ -25,6 +25,7 @@ public void launch(String[] args) { // Load all of the bots for every channel for (int i = 0; i < channels.length; i++) { new Bot(n.getToken(), channels[i]).connect(i == 0); + } } } diff --git a/src/main/java/org/jointheleague/modules/EquatonSolver.java b/src/main/java/org/jointheleague/modules/EquatonSolver.java new file mode 100644 index 00000000..2a831b16 --- /dev/null +++ b/src/main/java/org/jointheleague/modules/EquatonSolver.java @@ -0,0 +1,122 @@ +package org.jointheleague.modules; + +import java.util.ArrayList; +import java.util.Random; + +import org.javacord.api.event.message.MessageCreateEvent; + +import net.aksingh.owmjapis.api.APIException; + +public class EquatonSolver extends CustomMessageCreateListener { + private static final String command = "!equation"; + + public EquatonSolver(String channelName) { + super(channelName); + + } + + @Override + public void handle(MessageCreateEvent event) throws APIException { + // TODO Auto-generated method stub + + if (event.getMessageContent().contains("!equation")) { + String eqws = event.getMessageContent().substring(9); + String eq = ""; + for (int i = 0; i < eqws.length(); i++) { + if (eqws.charAt(i) == ' ') { + continue; + } else { + eq += eqws.charAt(i); + } + } + + String num = ""; + ArrayList hold; + + hold = new ArrayList(); + for (int i = 0; i < eq.length(); i++) { + if (eq.charAt(eq.length() - 1) == '+' || eq.charAt(eq.length() - 1) == '-' + || eq.charAt(eq.length() - 1) == '/' || eq.charAt(eq.length() - 1) == '*') { + System.out.println("Not A Valid Equation"); + System.exit(0); + } + + if (Character.isDigit(eq.charAt(i))) { + num += "" + eq.charAt(i); + + } else { + // int add = Integer.parseInt(num); + hold.add(num); + num = ""; + + } + + if (eq.charAt(i) == '+') { + hold.add("+"); + } + if (eq.charAt(i) == '-') { + hold.add("-"); + } + if (eq.charAt(i) == '*') { + hold.add("*"); + } + if (eq.charAt(i) == '/') { + hold.add("/"); + } + /* + * 5+6*7-8/2 5+42-8/2 5+42-4 47-4 43 + */ + } + hold.add(num); + num = ""; + + boolean done = false; + String[] symbols = { "*", "/", "+", "-" }; + int currentIndex = 0; + String currentSym = symbols[currentIndex]; + while (!done) { + boolean found = false; + + for (int i = 0; i < hold.size(); i++) { + if (hold.get(i).equals(currentSym)) { + double fVal = Double.parseDouble(hold.get(i - 1)); + double sVal = Double.parseDouble(hold.get(i + 1)); + double solution = 0; + if (hold.get(i).equals("*")) { + solution = fVal * sVal; + } + if (hold.get(i).equals("/")) { + solution = fVal / sVal; + } + if (hold.get(i).equals("+")) { + solution = fVal + sVal; + } + if (hold.get(i).equals("-")) { + solution = fVal - sVal; + } + hold.remove(i - 1); + hold.remove(i - 1); + String ans = "" + solution; + hold.set(i - 1, ans); + found = true; + break; + } + } + if (!found) { + currentIndex++; + + if (currentIndex >= symbols.length) { + done = true; + } else { + + currentSym = symbols[currentIndex]; + } + } + } + + event.getChannel().sendMessage(hold.get(0)); + } + + } + +} diff --git a/src/main/resources/config.json b/src/main/resources/config.json index 0b58c8d9..68f00549 100644 --- a/src/main/resources/config.json +++ b/src/main/resources/config.json @@ -1,4 +1,4 @@ { - "channels": ["channelName"], - "token": "discordToken" + "channels": ["louis_d_bot"], + "token": "NzYzOTIzMTk1NTk3ODE1ODI4.X3-w6g.GhPMK1tMHbeHgEYWRAcIuEAFOQM" } From b9c28c8896350e443b5fca00cdb8b388f79f44db Mon Sep 17 00:00:00 2001 From: league Date: Thu, 17 Jun 2021 18:28:32 -0700 Subject: [PATCH 07/10] added modulo and hold is adding parentheses --- .../jointheleague/modules/EquatonSolver.java | 25 ++++++++++++++----- src/main/resources/config.json | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jointheleague/modules/EquatonSolver.java b/src/main/java/org/jointheleague/modules/EquatonSolver.java index 2a831b16..c8f2082a 100644 --- a/src/main/java/org/jointheleague/modules/EquatonSolver.java +++ b/src/main/java/org/jointheleague/modules/EquatonSolver.java @@ -35,11 +35,6 @@ public void handle(MessageCreateEvent event) throws APIException { hold = new ArrayList(); for (int i = 0; i < eq.length(); i++) { - if (eq.charAt(eq.length() - 1) == '+' || eq.charAt(eq.length() - 1) == '-' - || eq.charAt(eq.length() - 1) == '/' || eq.charAt(eq.length() - 1) == '*') { - System.out.println("Not A Valid Equation"); - System.exit(0); - } if (Character.isDigit(eq.charAt(i))) { num += "" + eq.charAt(i); @@ -63,6 +58,16 @@ public void handle(MessageCreateEvent event) throws APIException { if (eq.charAt(i) == '/') { hold.add("/"); } + if (eq.charAt(i) == '%') { + hold.add("%"); + + } + if (eq.charAt(i) == '(') { + hold.add("("); + } + if (eq.charAt(i) == ')') { + hold.add(")"); + } /* * 5+6*7-8/2 5+42-8/2 5+42-4 47-4 43 */ @@ -71,7 +76,7 @@ public void handle(MessageCreateEvent event) throws APIException { num = ""; boolean done = false; - String[] symbols = { "*", "/", "+", "-" }; + String[] symbols = { "(", ")", "*", "/", "%", "+", "-" }; int currentIndex = 0; String currentSym = symbols[currentIndex]; while (!done) { @@ -84,15 +89,23 @@ public void handle(MessageCreateEvent event) throws APIException { double solution = 0; if (hold.get(i).equals("*")) { solution = fVal * sVal; + } if (hold.get(i).equals("/")) { solution = fVal / sVal; + } if (hold.get(i).equals("+")) { solution = fVal + sVal; + } if (hold.get(i).equals("-")) { solution = fVal - sVal; + + } + if (hold.get(i).equals("%")) { + solution = fVal % sVal; + } hold.remove(i - 1); hold.remove(i - 1); diff --git a/src/main/resources/config.json b/src/main/resources/config.json index 68f00549..c803cfb3 100644 --- a/src/main/resources/config.json +++ b/src/main/resources/config.json @@ -1,4 +1,4 @@ { "channels": ["louis_d_bot"], - "token": "NzYzOTIzMTk1NTk3ODE1ODI4.X3-w6g.GhPMK1tMHbeHgEYWRAcIuEAFOQM" + "token": "" } From 2d3a83780d6dfecd1c80cc9ee69ed3205a766cb5 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 8 Jul 2021 17:08:29 -0700 Subject: [PATCH 08/10] done --- .../jointheleague/modules/EquatonSolver.java | 99 ++++++++++--------- src/main/resources/config.json | 2 +- 2 files changed, 53 insertions(+), 48 deletions(-) diff --git a/src/main/java/org/jointheleague/modules/EquatonSolver.java b/src/main/java/org/jointheleague/modules/EquatonSolver.java index c8f2082a..1d7e3e70 100644 --- a/src/main/java/org/jointheleague/modules/EquatonSolver.java +++ b/src/main/java/org/jointheleague/modules/EquatonSolver.java @@ -75,61 +75,66 @@ public void handle(MessageCreateEvent event) throws APIException { hold.add(num); num = ""; - boolean done = false; - String[] symbols = { "(", ")", "*", "/", "%", "+", "-" }; - int currentIndex = 0; - String currentSym = symbols[currentIndex]; - while (!done) { - boolean found = false; - - for (int i = 0; i < hold.size(); i++) { - if (hold.get(i).equals(currentSym)) { - double fVal = Double.parseDouble(hold.get(i - 1)); - double sVal = Double.parseDouble(hold.get(i + 1)); - double solution = 0; - if (hold.get(i).equals("*")) { - solution = fVal * sVal; - - } - if (hold.get(i).equals("/")) { - solution = fVal / sVal; - - } - if (hold.get(i).equals("+")) { - solution = fVal + sVal; - - } - if (hold.get(i).equals("-")) { - solution = fVal - sVal; - - } - if (hold.get(i).equals("%")) { - solution = fVal % sVal; - - } - hold.remove(i - 1); - hold.remove(i - 1); - String ans = "" + solution; - hold.set(i - 1, ans); - found = true; - break; + } + + } + + public void solveEquation(ArrayList hold) { + boolean done = false; + String[] symbols = { "*", "/", "%", "+", "-" }; + int currentIndex = 0; + String currentSym = symbols[currentIndex]; + while (!done) { + boolean found = false; + + for (int i = 0; i < hold.size(); i++) { + System.out.println(hold.get(i)); + if (hold.get(i).equals(currentSym)) { + double fVal = Double.parseDouble(hold.get(i - 1)); + double sVal = Double.parseDouble(hold.get(i + 1)); + double solution = 0; + + if (hold.get(i).equals("*")) { + solution = fVal * sVal; + } - } - if (!found) { - currentIndex++; + if (hold.get(i).equals("/")) { + solution = fVal / sVal; - if (currentIndex >= symbols.length) { - done = true; - } else { + } + if (hold.get(i).equals("+")) { + solution = fVal + sVal; - currentSym = symbols[currentIndex]; } + if (hold.get(i).equals("-")) { + solution = fVal - sVal; + + } + if (hold.get(i).equals("%")) { + solution = fVal % sVal; + + } + + hold.remove(i - 1); + hold.remove(i - 1); + String ans = "" + solution; + hold.set(i - 1, ans); + found = true; + break; } } + if (!found) { + currentIndex++; - event.getChannel().sendMessage(hold.get(0)); + if (currentIndex >= symbols.length) { + done = true; + } else { + + currentSym = symbols[currentIndex]; + } + } } + event.getChannel().sendMessage(hold.get(0)); } - } diff --git a/src/main/resources/config.json b/src/main/resources/config.json index c803cfb3..f6701a89 100644 --- a/src/main/resources/config.json +++ b/src/main/resources/config.json @@ -1,4 +1,4 @@ { "channels": ["louis_d_bot"], - "token": "" + "token": "NzYzOTIzMTk1NTk3ODE1ODI4.X3-w6g.91rfYIwPLanISXJXxQNzJd3pXMI" } From f8dd4f0b15d1c20d44cfd8824ff3119614d1b050 Mon Sep 17 00:00:00 2001 From: league Date: Thu, 8 Jul 2021 18:28:11 -0700 Subject: [PATCH 09/10] check for random spaces when parentheses are used because they don't show up in the normal equations need to sort that out then remove the equation within the parentheses that is already solved --- .../jointheleague/modules/EquatonSolver.java | 37 ++++++++++++++----- src/main/resources/config.json | 2 +- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/jointheleague/modules/EquatonSolver.java b/src/main/java/org/jointheleague/modules/EquatonSolver.java index 1d7e3e70..6bc170f1 100644 --- a/src/main/java/org/jointheleague/modules/EquatonSolver.java +++ b/src/main/java/org/jointheleague/modules/EquatonSolver.java @@ -32,7 +32,8 @@ public void handle(MessageCreateEvent event) throws APIException { String num = ""; ArrayList hold; - + int start = -1; + int end = -1; hold = new ArrayList(); for (int i = 0; i < eq.length(); i++) { @@ -64,31 +65,48 @@ public void handle(MessageCreateEvent event) throws APIException { } if (eq.charAt(i) == '(') { hold.add("("); + start = i; + start++; } if (eq.charAt(i) == ')') { hold.add(")"); + end = i; } - /* - * 5+6*7-8/2 5+42-8/2 5+42-4 47-4 43 - */ + } +// ArrayList input = new ArrayList(); +// +// for (int i = start; i < end; i++) { +// +// input.add("" + eq.charAt(i)); +// +// +// } +// +// +// hold.add(num); num = ""; - +// solveEquation(input); +// System.out.println("input " +solveEquation(input)); +// hold.add(0, solveEquation(input)); + System.out.println("hold is " + hold); + event.getChannel().sendMessage(solveEquation(hold)); } } - public void solveEquation(ArrayList hold) { + public String solveEquation(ArrayList hold) { + boolean done = false; - String[] symbols = { "*", "/", "%", "+", "-" }; + String[] symbols = { "*", "/", "%", "-", "+" }; int currentIndex = 0; String currentSym = symbols[currentIndex]; while (!done) { boolean found = false; for (int i = 0; i < hold.size(); i++) { - System.out.println(hold.get(i)); + if (hold.get(i).equals(currentSym)) { double fVal = Double.parseDouble(hold.get(i - 1)); double sVal = Double.parseDouble(hold.get(i + 1)); @@ -134,7 +152,8 @@ public void solveEquation(ArrayList hold) { } } } + String ans = hold.get(0); + return (ans); - event.getChannel().sendMessage(hold.get(0)); } } diff --git a/src/main/resources/config.json b/src/main/resources/config.json index f6701a89..cec4f56f 100644 --- a/src/main/resources/config.json +++ b/src/main/resources/config.json @@ -1,4 +1,4 @@ { "channels": ["louis_d_bot"], - "token": "NzYzOTIzMTk1NTk3ODE1ODI4.X3-w6g.91rfYIwPLanISXJXxQNzJd3pXMI" + "token": "NzYzOTIzMTk1NTk3ODE1ODI4.X3-w6g.pGKkh1EKOq9SAK8yDKjkIPaJWDw" } From d0e029f207f4136351313be7f3831032e263f017 Mon Sep 17 00:00:00 2001 From: league Date: Thu, 15 Jul 2021 18:28:59 -0700 Subject: [PATCH 10/10] need to work on remoing the leftovers of hold in the solveParenth method --- .../jointheleague/modules/EquatonSolver.java | 66 +++++++++++++++---- src/main/resources/config.json | 2 +- 2 files changed, 53 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/jointheleague/modules/EquatonSolver.java b/src/main/java/org/jointheleague/modules/EquatonSolver.java index 6bc170f1..f1defb1e 100644 --- a/src/main/java/org/jointheleague/modules/EquatonSolver.java +++ b/src/main/java/org/jointheleague/modules/EquatonSolver.java @@ -27,23 +27,29 @@ public void handle(MessageCreateEvent event) throws APIException { continue; } else { eq += eqws.charAt(i); + } } - + //eq is good here String num = ""; ArrayList hold; - int start = -1; - int end = -1; + hold = new ArrayList(); for (int i = 0; i < eq.length(); i++) { - + if (Character.isDigit(eq.charAt(i))) { + num=""; num += "" + eq.charAt(i); } else { + if(num.equals("")) { + + } // int add = Integer.parseInt(num); + else { hold.add(num); - num = ""; + } + } @@ -65,12 +71,9 @@ public void handle(MessageCreateEvent event) throws APIException { } if (eq.charAt(i) == '(') { hold.add("("); - start = i; - start++; } if (eq.charAt(i) == ')') { hold.add(")"); - end = i; } } @@ -85,12 +88,11 @@ public void handle(MessageCreateEvent event) throws APIException { // // // - hold.add(num); - num = ""; + // solveEquation(input); // System.out.println("input " +solveEquation(input)); // hold.add(0, solveEquation(input)); - System.out.println("hold is " + hold); + event.getChannel().sendMessage(solveEquation(hold)); } @@ -99,14 +101,14 @@ public void handle(MessageCreateEvent event) throws APIException { public String solveEquation(ArrayList hold) { boolean done = false; - String[] symbols = { "*", "/", "%", "-", "+" }; + String[] symbols = {"*", "/", "%", "-", "+" }; int currentIndex = 0; String currentSym = symbols[currentIndex]; while (!done) { boolean found = false; for (int i = 0; i < hold.size(); i++) { - +//System.out.println("hold.geti is " + hold.get(i)); if (hold.get(i).equals(currentSym)) { double fVal = Double.parseDouble(hold.get(i - 1)); double sVal = Double.parseDouble(hold.get(i + 1)); @@ -132,7 +134,8 @@ public String solveEquation(ArrayList hold) { solution = fVal % sVal; } - + + hold.remove(i - 1); hold.remove(i - 1); String ans = "" + solution; @@ -140,6 +143,11 @@ public String solveEquation(ArrayList hold) { found = true; break; } + if(hold.get(i).equals("(")) { + + solveParenth(hold, i); + } + } if (!found) { currentIndex++; @@ -156,4 +164,34 @@ public String solveEquation(ArrayList hold) { return (ans); } + public void solveParenth(ArrayList hold, int place) { + ArrayList in = new ArrayList(); + int end = -1; + for(int i = place+=1;i