From 251811ff2061707f1042b7bec9a1e93e3963bb21 Mon Sep 17 00:00:00 2001 From: Halqq Date: Thu, 15 Sep 2022 22:05:25 -0300 Subject: [PATCH] added all files --- .gitignore | 2 + .idea/.gitignore | 3 + .idea/artifacts/MathResolver_jar.xml | 8 ++ .idea/misc.xml | 6 + .idea/modules.xml | 8 ++ .idea/uiDesigner.xml | 124 ++++++++++++++++++++ MathResolver.iml | 11 ++ src/META-INF/MANIFEST.MF | 3 + src/dev/halq/Calculator/Calculator.java | 55 +++++++++ src/dev/halq/Calculator/Utils/CalcUtil.java | 42 +++++++ src/dev/halq/Equation/EquationResolver.java | 64 ++++++++++ src/dev/halq/Main.java | 51 ++++++++ src/dev/halq/Utils/CmdUtil.java | 17 +++ 13 files changed, 394 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/artifacts/MathResolver_jar.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 MathResolver.iml create mode 100644 src/META-INF/MANIFEST.MF create mode 100644 src/dev/halq/Calculator/Calculator.java create mode 100644 src/dev/halq/Calculator/Utils/CalcUtil.java create mode 100644 src/dev/halq/Equation/EquationResolver.java create mode 100644 src/dev/halq/Main.java create mode 100644 src/dev/halq/Utils/CmdUtil.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..21b4487 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Project exclude paths +/out/ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/artifacts/MathResolver_jar.xml b/.idea/artifacts/MathResolver_jar.xml new file mode 100644 index 0000000..aaa1dc7 --- /dev/null +++ b/.idea/artifacts/MathResolver_jar.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/out/artifacts/MathResolver_jar + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /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..8f13aa7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MathResolver.iml b/MathResolver.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/MathResolver.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..893b728 --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: dev.halq.Main + diff --git a/src/dev/halq/Calculator/Calculator.java b/src/dev/halq/Calculator/Calculator.java new file mode 100644 index 0000000..5a73d9e --- /dev/null +++ b/src/dev/halq/Calculator/Calculator.java @@ -0,0 +1,55 @@ +package dev.halq.Calculator; + +import dev.halq.Calculator.Utils.CalcUtil; + +import java.util.Scanner; + +import static dev.halq.Utils.CmdUtil.print; + +/** + * @author Halq + * @since 15/09/2022 + */ + +public class Calculator { + + public static void calculatorMain() { + double firstvalue, secondvalue; + + String op = null; + Scanner reader = new Scanner(System.in); + + print("Please put first number"); + + if (!reader.hasNextDouble()) { + print("Please put valid value"); + reader.hasNextDouble(); + + } + + firstvalue = reader.nextDouble(); + + print("Please put math operator"); + + op = reader.next(); + + if (!(op.equals("+") || op.equals("-") || op.equals("+") || op.equals("/") || op.equals("%"))) { + print("Please put valid operator"); + + } + + print("Please put second number"); + + if (!reader.hasNextDouble()) { + print("Please put valid value"); + reader.hasNextDouble(); + + } + + secondvalue = reader.nextDouble(); + + print("Result: "); + CalcUtil.calcq(op, firstvalue, secondvalue); + + } +} \ No newline at end of file diff --git a/src/dev/halq/Calculator/Utils/CalcUtil.java b/src/dev/halq/Calculator/Utils/CalcUtil.java new file mode 100644 index 0000000..e4cd32b --- /dev/null +++ b/src/dev/halq/Calculator/Utils/CalcUtil.java @@ -0,0 +1,42 @@ +package dev.halq.Calculator.Utils; + +import static dev.halq.Utils.CmdUtil.*; + +/** + * @author Halq + * @since 15/09/2022 + */ + +public class CalcUtil { + + public static void calcq(String operator, double value, double value2){ + switch (operator){ + + case "*": + calc(value * value2); + break; + + case "+": + calc(value + value2); + break; + + case "-": + calc(value - value2); + break; + + case "/": + if(value == 0 || value2 == 0) { + print("Impossible to divide number by 0"); + + } else { + calc(value / value2); + + } + break; + + case "%": + calc(value % value2); + break; + } + } +} \ No newline at end of file diff --git a/src/dev/halq/Equation/EquationResolver.java b/src/dev/halq/Equation/EquationResolver.java new file mode 100644 index 0000000..1e05683 --- /dev/null +++ b/src/dev/halq/Equation/EquationResolver.java @@ -0,0 +1,64 @@ +package dev.halq.Equation; + +import java.util.Scanner; + +import static dev.halq.Utils.CmdUtil.print; + +/** + * @author Halq + * @since 15/09/2022 + */ + +public class EquationResolver { + + public static void main() { + Scanner reader = new Scanner(System.in); + + double a, b, c; + + print("Please give me constants"); + + print("Ex: 2x - 3x - 5 = 0 , a: 2 b: -3 c: -5"); + + print("a:"); + if (!reader.hasNextDouble()) { + print("Please give valid value"); + reader.hasNextDouble(); + + } + + a = reader.nextDouble(); + + print("b:"); + if (!reader.hasNextDouble()) { + print("Please give valid value"); + reader.hasNextDouble(); + + } + + b = reader.nextDouble(); + + print("c:"); + if (!reader.hasNextDouble()) { + print("Please give valid value"); + reader.hasNextDouble(); + + } + + c = reader.nextDouble(); + + if (a != 0) { + double r = (c - b) / a; + + print("Answer = " + r); + + } else if (b == c) { + print("Answer = all x"); + + } else { + print("Invalid equation"); + + } + } + +} \ No newline at end of file diff --git a/src/dev/halq/Main.java b/src/dev/halq/Main.java new file mode 100644 index 0000000..943d0ef --- /dev/null +++ b/src/dev/halq/Main.java @@ -0,0 +1,51 @@ +package dev.halq; + +import dev.halq.Calculator.Calculator; +import dev.halq.Equation.EquationResolver; + +import java.util.Scanner; +import java.util.concurrent.TimeUnit; + +import static dev.halq.Utils.CmdUtil.print; + +/** + * @author Halq + * @since 15/09/2022 + */ + +public class Main { + + + public static void main(String[] args) throws InterruptedException { + + + Scanner reader = new Scanner(System.in); + + String r = null; + + print("Welcome for my MathResolver!!" + " Made by Halq!"); + TimeUnit.SECONDS.sleep(1); + + print("Wait.. loading MathResolver resources"); + TimeUnit.SECONDS.sleep(3); + + print("Calculator or Equation?"); + + r = reader.next(); + + if (r.equals("Calculator")) { + print("Loading calculator..."); + TimeUnit.SECONDS.sleep(2); + Calculator.calculatorMain(); + + } else if (r.equals("Equation")) { + print("Loading Equation Resolver..."); + TimeUnit.SECONDS.sleep(2); + EquationResolver.main(); + + } else { + print("Please put valid value (Calculator or Equation)"); + } + + } +} \ No newline at end of file diff --git a/src/dev/halq/Utils/CmdUtil.java b/src/dev/halq/Utils/CmdUtil.java new file mode 100644 index 0000000..5b453d5 --- /dev/null +++ b/src/dev/halq/Utils/CmdUtil.java @@ -0,0 +1,17 @@ +package dev.halq.Utils; + +/** + * @author Halq + * @since 15/09/2022 + */ + +public class CmdUtil { + + public static void print(String message){ + System.out.println(message); + } + + public static void calc(Double value){ + System.out.println(value); + } +}