From 880bd853ee25e1af2096b77ce581e48654ee4acb Mon Sep 17 00:00:00 2001 From: Chris Farmer Date: Sat, 8 Feb 2020 12:56:00 -0500 Subject: [PATCH 01/17] added base features --- .../scientificcalculator/Features.java | 76 +++++++++++++++++++ .../scientificcalculator/SciFeatures.java | 5 ++ 2 files changed, 81 insertions(+) create mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/Features.java create mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Features.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Features.java new file mode 100644 index 00000000..3e86caeb --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Features.java @@ -0,0 +1,76 @@ +package com.zipcodewilmington.scientificcalculator; + +import java.util.ArrayList; +import java.util.List; + +import static java.lang.Math.pow; +import static java.lang.Math.sqrt; + +public class Features{ + + public Features() { + } + + public double add(double a, double b) { + return a + b; + } + + public double substract(double a, double b) { + return a - b; + } + + public double multiply(double a, double b) { + return a * b; + } + + public double divide(double a, double b) { + return a / b; + } + + public double square(double a) { + return a * a; + } + + public double root(double a) { + return sqrt(a); + } + + public double exponent(double a, double b) { + return pow(a, b); + } + + public double inverse(double a) { + return 1 / a; + } + + public double invert(double a) { + return a * -1; + } + + public double clear() { + return 0; + } + + public void switchDisplayMode() { + if (displayMode.equals("binary")) { + displayMode = "octal"; + } else if (displayMode.equals("octal")) { + displayMode = "decimal"; + } else if (displayMode.equals("decimal")) { + displayMode = "hexadecimal"; + } else { + displayMode = "binary"; + } + } + + public void switchDisplayMode(String mode) { + displayMode = mode; + } + + public void storeMemory() { + List memory = new ArrayList; + } + + +} + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java new file mode 100644 index 00000000..d79540db --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java @@ -0,0 +1,5 @@ +package com.zipcodewilmington.scientificcalculator; + +public class SciFeatures { + +} From a7762d94c74f41c5728f246c666407996901eb57 Mon Sep 17 00:00:00 2001 From: Chris Farmer Date: Sat, 8 Feb 2020 12:59:14 -0500 Subject: [PATCH 02/17] added base features --- .../scientificcalculator/Features.java | 22 ---------------- .../scientificcalculator/SciFeatures.java | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Features.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Features.java index 3e86caeb..228bf264 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Features.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Features.java @@ -50,27 +50,5 @@ public double invert(double a) { public double clear() { return 0; } - - public void switchDisplayMode() { - if (displayMode.equals("binary")) { - displayMode = "octal"; - } else if (displayMode.equals("octal")) { - displayMode = "decimal"; - } else if (displayMode.equals("decimal")) { - displayMode = "hexadecimal"; - } else { - displayMode = "binary"; - } - } - - public void switchDisplayMode(String mode) { - displayMode = mode; - } - - public void storeMemory() { - List memory = new ArrayList; - } - - } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java index d79540db..f4588f5f 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java @@ -1,5 +1,31 @@ package com.zipcodewilmington.scientificcalculator; +import java.util.ArrayList; +import java.util.List; + public class SciFeatures { + String displayMode; + + public void switchDisplayMode() { + if (displayMode.equals("binary")) { + displayMode = "octal"; + } else if (displayMode.equals("octal")) { + displayMode = "decimal"; + } else if (displayMode.equals("decimal")) { + displayMode = "hexadecimal"; + } else { + displayMode = "binary"; + } + } + + public void switchDisplayMode(String mode) { + displayMode = mode; + } + + public void storeMemory() { + List memory = new ArrayList; + } + + } From 3952b30b67ecb949740e0358f1db8e7e38817de2 Mon Sep 17 00:00:00 2001 From: Chris Farmer Date: Sat, 8 Feb 2020 14:17:34 -0500 Subject: [PATCH 03/17] more changes to scifeatures --- .../scientificcalculator/Features.java | 2 + .../scientificcalculator/SciFeatures.java | 55 +++++++++++++++++-- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Features.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Features.java index 228bf264..62b48795 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Features.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Features.java @@ -50,5 +50,7 @@ public double invert(double a) { public double clear() { return 0; } + + } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java index f4588f5f..ace9ff3b 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java @@ -1,12 +1,19 @@ package com.zipcodewilmington.scientificcalculator; import java.util.ArrayList; -import java.util.List; + +import static java.lang.Math.*; public class SciFeatures { + public SciFeatures(){ + } + + String unitsMode; String displayMode; - + ArrayList memory; + + public void switchDisplayMode() { if (displayMode.equals("binary")) { displayMode = "octal"; @@ -23,9 +30,49 @@ public void switchDisplayMode(String mode) { displayMode = mode; } - public void storeMemory() { - List memory = new ArrayList; + public void storeMemory(double a) { + memory.set(0, a); + } + + public void clearMemory() { + memory.set(0, null); + } + + public double memoryRecall() { + return memory.get(0); + } + + public double sine(double a) { + return sin(a); + } + + public double cosine(double a) { + return cos(a); + } + + public double tangent(double a) { + return tan(a); + } + + public double sineInverse(double a) { + return asin(a); + } + + public double cosineInverse(double a) { + return acos(a); + } + + public double tangentInverse(double a) { + return atan(a); } + public void switchUnitsMode() { + if (unitsMode.equals("Degrees")) { + unitsMode = "Radians"; + } + else { + displayMode = "Degrees"; + } + } } From a894ba2a12d2cfdbf1c3dac9e7f1485f0b4b6f27 Mon Sep 17 00:00:00 2001 From: Chris Farmer Date: Sat, 8 Feb 2020 14:50:21 -0500 Subject: [PATCH 04/17] first merge --- .../scientificcalculator/SciFeatures.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java index ace9ff3b..0e16f483 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java @@ -71,8 +71,23 @@ public void switchUnitsMode() { unitsMode = "Radians"; } else { - displayMode = "Degrees"; + unitsMode = "Degrees"; } } + public void switchUnitsMode(String mode){ + unitsMode = mode; + } + + public double log(double a) { + return Math.log10(a); + } + + public double inverseLog(double a) { + return exp(a); + } + + public double naturalLog(double a) { + return Math.log(a); + } } From 654f0a61c49a7a980bd6bd568f868229dac47421 Mon Sep 17 00:00:00 2001 From: Chris Farmer Date: Sat, 8 Feb 2020 17:07:46 -0500 Subject: [PATCH 05/17] progress slowly --- pom.xml | 8 ++++ .../scientificcalculator/Features.java | 5 ++- .../scientificcalculator/SciFeatures.java | 20 ++++++++- .../SciFeaturesTest.java | 45 +++++++++++++++++++ .../TestMainApplication.java | 7 +++ 5 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java diff --git a/pom.xml b/pom.xml index e7cb4f6b..d8cd763e 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,14 @@ com.zipcodewilmington scientific_calculator 1.0-SNAPSHOT + + + junit + junit + 4.12 + test + + \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Features.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Features.java index 62b48795..69fd1a98 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Features.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Features.java @@ -15,7 +15,7 @@ public double add(double a, double b) { return a + b; } - public double substract(double a, double b) { + public double subtract(double a, double b) { return a - b; } @@ -47,10 +47,11 @@ public double invert(double a) { return a * -1; } - public double clear() { + public int clear() { return 0; } + } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java index 0e16f483..615d5531 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java @@ -13,6 +13,12 @@ public SciFeatures(){ String displayMode; ArrayList memory; + public void setDisplayMode(String a) { + this.displayMode = a; + } + public String getDisplayMode(){ + return this.displayMode; + } public void switchDisplayMode() { if (displayMode.equals("binary")) { @@ -80,7 +86,7 @@ public void switchUnitsMode(String mode){ } public double log(double a) { - return Math.log10(a); + return log10(a); } public double inverseLog(double a) { @@ -88,6 +94,16 @@ public double inverseLog(double a) { } public double naturalLog(double a) { - return Math.log(a); + return log(a); + } + + + + public int factorial(int a) { + int sum = 1; + for (int i = 2; i <= a; i++){ + sum *= i; + } + return sum; } } diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java new file mode 100644 index 00000000..9a123c80 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java @@ -0,0 +1,45 @@ +package com.zipcodewilmington.scientific_calculator; + +import com.zipcodewilmington.scientificcalculator.SciFeatures; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +public class SciFeaturesTest { + SciFeatures test = new SciFeatures(); + + @Test + public void switchTest(){ + test.setDisplayMode("decimal"); + test.switchDisplayMode(); + assertEquals("hexadecimal", test.getDisplayMode()); + } + @Test + public void switchTest1(){ + test.setDisplayMode("binary"); + test.switchDisplayMode(); + assertEquals("octal", test.getDisplayMode()); + } + @Test + public void switchTest2(){ + test.setDisplayMode("hexadecimal"); + test.switchDisplayMode(); + assertEquals("binary", test.getDisplayMode()); + } + @Test + public void switchTest3(){ + test.setDisplayMode("octal"); + test.switchDisplayMode(); + assertEquals("decimal", test.getDisplayMode()); + } + @Test + public void switchTest4(){ + test.setDisplayMode("decimal"); + test.switchDisplayMode("hexadecimal"); + assertEquals("hexadecimal", test.getDisplayMode()); + } + @Test + public void memoryTest(){ + test.storeMemory(2); + assertEquals(2, test.memoryRecall()); + } +} diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java index 94e8d987..1b20571c 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java @@ -1,7 +1,14 @@ package com.zipcodewilmington.scientific_calculator; +import com.zipcodewilmington.scientificcalculator.Features; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + /** * Created by leon on 2/9/18. */ public class TestMainApplication { + + } From 9c1c7c021ad79a725f4d11643dc3f830366720f1 Mon Sep 17 00:00:00 2001 From: Chris Farmer Date: Sat, 8 Feb 2020 18:39:01 -0500 Subject: [PATCH 06/17] added code from main --- .../scientificcalculator/Console.java | 42 +++++++-- .../scientificcalculator/MainApplication.java | 86 +++++++++++++++++-- .../scientificcalculator/SciFeatures.java | 6 +- .../SciFeaturesTest.java | 6 +- .../TestMainApplication.java | 7 -- 5 files changed, 117 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index 83f0e97f..8ffdebd5 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -15,18 +15,42 @@ public static void println(String output, Object... args) { print(output + "\n", args); } - public static String getStringInput(String prompt) { - Scanner scanner = new Scanner(System.in); - println(prompt); - String userInput = scanner.nextLine(); - return userInput; + public static String getStringInput(String prompt) + { + Scanner username = new Scanner(System.in); + println (prompt); + String user = username.nextLine(); + System.out.println("Hello " + user + " !"); + return user; } - public static Integer getIntegerInput(String prompt) { - return null; + public static Double getDoubleInput(String prompt) + { + Scanner number = new Scanner(System.in); + println (prompt); + Double num = number.nextDouble(); + return num; } - public static Double getDoubleInput(String prompt) { - return null; + public static String getOperationInput(String prompt) + { + Scanner operation = new Scanner(System.in); + println (prompt); + String ops = operation.nextLine(); + return ops; } + + + + + + + + //public static Integer getIntegerInput(String prompt) { + //return null; } + +//public static Double getDoubleInput(String prompt) { +//return null; +//} +//} diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 5f421325..a05ac681 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -1,17 +1,91 @@ package com.zipcodewilmington.scientificcalculator; +import java.util.Scanner; + /** * Created by leon on 2/9/18. */ public class MainApplication { public static void main(String[] args) { + + + Features f = new Features(); + Console.println("Welcome to my calculator!"); - String s = Console.getStringInput("Enter a string"); - Integer i = Console.getIntegerInput("Enter an integer"); - Double d = Console.getDoubleInput("Enter a double."); - Console.println("The user input %s as a string", s); - Console.println("The user input %s as a integer", i); - Console.println("The user input %s as a d", d); + String s = Console.getStringInput(" Please enter your name?"); + + int display = 0; + Console.println("Current number is :" + display); + + Double i = Console.getDoubleInput("Please enter a number:"); + + boolean check = true; + while (check) + { + String op = Console.getOperationInput("Enter an operation : +, - , *, /, ^2, ^y, inverse, sqrt, invert, c, end : "); + + + if (op.equals("+")) { + Double i1 = Console.getDoubleInput("Please next number:"); + Console.println("New Value is: " + f.add(i, i1)); + i = f.add(i, i1); + } else if (op.equals("-")) { + Double i1 = Console.getDoubleInput("Please next number:"); + Console.println("New Value is:" + f.subtract(i, i1)); + } else if (op.equals("*")) { + Double i1 = Console.getDoubleInput("Please next number:"); + Console.println("New Value is:" + f.multiply(i, i1)); + } else if (op.equals("/")) + { + Double i1 = Console.getDoubleInput("Please next number:"); + if (i1 == 0) { + Console.println("Err"); + } + else { + Console.println("New Value is:" + f.divide(i, i1)); + } + } else if (op.equals("^y")) { + Double i1 = Console.getDoubleInput("Please next number:"); + Console.println("New Value is:" + f.exponent(i, i1)); + + } else if (op.equals("^2")) { + Console.println("New Value is:" + f.square(i)); + } else if (op.equals("sqrt")) { + Console.println("New Value is:" + f.root(i)); + } else if (op.equals("inverse")) { + Console.println("New Value is:" + f.inverse(i)); + } else if (op.equals("invert")) { + Console.println("New Value is:" + f.invert(i)); + } else if (op.equals("c")) { + Console.println("New Value is:" + f.clear()); + } else if (op.equals("end")) + { + check = false; + } + else { + Console.println("Err"); + } + + + //Scanner username = new Scanner(System.in); + //String user = username.nextLine(); + //System.out.print("Hello " + user + " !"); + + + //Double i = Console.getDoubleInput("Enter a number"); + //Scanner number = new Scanner(System.in); + //int + + + //String s = Console.getStringInput("Enter a string"); + //Double i = Console.getDoubleInput("Enter an Double"); + //Double d = Console.getDoubleInput("Enter a double."); + + //Console.println("Hello" + s); + //Console.println("The user input %s as a Double", i); + //Console.println("The user input %s as a d", d); + } } } + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java index 615d5531..de58d672 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java @@ -9,9 +9,9 @@ public class SciFeatures { public SciFeatures(){ } - String unitsMode; - String displayMode; - ArrayList memory; + private String unitsMode; + private String displayMode; + private ArrayList memory = new ArrayList<>(); public void setDisplayMode(String a) { this.displayMode = a; diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java index 9a123c80..cc4c14d9 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java @@ -37,9 +37,5 @@ public void switchTest4(){ test.switchDisplayMode("hexadecimal"); assertEquals("hexadecimal", test.getDisplayMode()); } - @Test - public void memoryTest(){ - test.storeMemory(2); - assertEquals(2, test.memoryRecall()); - } + } diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java index 1b20571c..94e8d987 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java @@ -1,14 +1,7 @@ package com.zipcodewilmington.scientific_calculator; -import com.zipcodewilmington.scientificcalculator.Features; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - /** * Created by leon on 2/9/18. */ public class TestMainApplication { - - } From c582545b690535e774bf727f27b3e272493eda44 Mon Sep 17 00:00:00 2001 From: Chris Farmer Date: Sat, 8 Feb 2020 19:22:30 -0500 Subject: [PATCH 07/17] added more stuff --- .../scientificcalculator/SciFeatures.java | 14 ++++++++++++-- .../scientific_calculator/SciFeaturesTest.java | 6 ++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java index de58d672..b4b758af 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java @@ -72,6 +72,10 @@ public double tangentInverse(double a) { return atan(a); } + public double toRadian(double a){ + return toRadians(a); + } + public void switchUnitsMode() { if (unitsMode.equals("Degrees")) { unitsMode = "Radians"; @@ -85,7 +89,7 @@ public void switchUnitsMode(String mode){ unitsMode = mode; } - public double log(double a) { + public double logarithm(double a) { return log10(a); } @@ -94,7 +98,11 @@ public double inverseLog(double a) { } public double naturalLog(double a) { - return log(a); + return Math.log(a); + } + + public double inverseNaturalLog(double a){ + return Math.pow(10, a); } @@ -106,4 +114,6 @@ public int factorial(int a) { } return sum; } + + public String } diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java index cc4c14d9..9d9e30b5 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java @@ -38,4 +38,10 @@ public void switchTest4(){ assertEquals("hexadecimal", test.getDisplayMode()); } + @Test + public void memoryTest(){ + test.storeMemory(2); + assertEquals(2, test.memoryRecall()); + } + } From aa2e154420e0bbdbfb06d8965407d5f59c919b1f Mon Sep 17 00:00:00 2001 From: Chris Farmer Date: Sat, 8 Feb 2020 19:36:48 -0500 Subject: [PATCH 08/17] finished scifeatures --- .../scientificcalculator/SciFeatures.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java index b4b758af..280dcc71 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java @@ -1,6 +1,7 @@ package com.zipcodewilmington.scientificcalculator; -import java.util.ArrayList; + +import java.util.Stack; import static java.lang.Math.*; @@ -11,7 +12,7 @@ public SciFeatures(){ private String unitsMode; private String displayMode; - private ArrayList memory = new ArrayList<>(); + private Stack s; public void setDisplayMode(String a) { this.displayMode = a; @@ -32,20 +33,24 @@ public void switchDisplayMode() { } } + + public void switchDisplayMode(String mode) { displayMode = mode; } public void storeMemory(double a) { - memory.set(0, a); + s.push(a); } public void clearMemory() { - memory.set(0, null); + if (s.empty() == false) { + s.pop(); + } } - public double memoryRecall() { - return memory.get(0); + public double memoryRecall(){ + return (double) s.peek(); } public double sine(double a) { @@ -115,5 +120,5 @@ public int factorial(int a) { return sum; } - public String + } From 7b1e3a7e48025e4aa8ff31fc495df955834603e0 Mon Sep 17 00:00:00 2001 From: Chris Farmer Date: Sat, 8 Feb 2020 21:34:50 -0500 Subject: [PATCH 09/17] may have done some noob stuff --- .../scientificcalculator/MainApplication.java | 126 ++++++++---------- .../scientificcalculator/SciFeatures.java | 12 +- .../scientific_calculator/FeaturesTest.java | 108 +++++++++++++++ .../SciFeaturesTest.java | 2 +- 4 files changed, 174 insertions(+), 74 deletions(-) create mode 100644 src/test/java/com/zipcodewilmington/scientific_calculator/FeaturesTest.java diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index a05ac681..fd084bd1 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -10,82 +10,74 @@ public static void main(String[] args) { Features f = new Features(); + SciFeatures sf = new SciFeatures(); Console.println("Welcome to my calculator!"); - String s = Console.getStringInput(" Please enter your name?"); + String s = Console.getStringInput("Please enter your name?"); int display = 0; - Console.println("Current number is :" + display); - - Double i = Console.getDoubleInput("Please enter a number:"); - - boolean check = true; - while (check) - { - String op = Console.getOperationInput("Enter an operation : +, - , *, /, ^2, ^y, inverse, sqrt, invert, c, end : "); - - - if (op.equals("+")) { - Double i1 = Console.getDoubleInput("Please next number:"); - Console.println("New Value is: " + f.add(i, i1)); - i = f.add(i, i1); - } else if (op.equals("-")) { - Double i1 = Console.getDoubleInput("Please next number:"); - Console.println("New Value is:" + f.subtract(i, i1)); - } else if (op.equals("*")) { - Double i1 = Console.getDoubleInput("Please next number:"); - Console.println("New Value is:" + f.multiply(i, i1)); - } else if (op.equals("/")) - { - Double i1 = Console.getDoubleInput("Please next number:"); - if (i1 == 0) { - Console.println("Err"); + int r = 1; + do { + try { + Double calcString = Console.getDoubleInput("Press 1 for base calculator and 2 for scientific calculator. "); + + if (calcString == 1) { + Console.println("Current number is :" + display); + + Double i = Console.getDoubleInput("Please enter another number if you want:"); + + boolean check = true; + while (check) { + String op = Console.getOperationInput("Enter an operation : +, - , *, /, ^2, ^y, inverse, sqrt, invert, c, end : "); + + + if (op.equals("+")) { + Double i1 = Console.getDoubleInput("Please next number:"); + Console.println("New Value is: " + f.add(i, i1)); + i = f.add(i, i1); + } else if (op.equals("-")) { + Double i1 = Console.getDoubleInput("Please next number:"); + Console.println("New Value is:" + f.subtract(i, i1)); + } else if (op.equals("*")) { + Double i1 = Console.getDoubleInput("Please next number:"); + Console.println("New Value is:" + f.multiply(i, i1)); + } else if (op.equals("/")) { + Double i1 = Console.getDoubleInput("Please next number:"); + if (i1 == 0) { + Console.println("Err"); + } else { + Console.println("New Value is:" + f.divide(i, i1)); + } + } else if (op.equals("^y")) { + Double i1 = Console.getDoubleInput("Please next number:"); + Console.println("New Value is:" + f.exponent(i, i1)); + + } else if (op.equals("^2")) { + Console.println("New Value is:" + f.square(i)); + } else if (op.equals("sqrt")) { + Console.println("New Value is:" + f.root(i)); + } else if (op.equals("inverse")) { + Console.println("New Value is:" + f.inverse(i)); + } else if (op.equals("invert")) { + Console.println("New Value is:" + f.invert(i)); + } else if (op.equals("c")) { + Console.println("New Value is:" + f.clear()); + } else if (op.equals("end")) { + check = false; + } else { + Console.println("Err"); + } + } + } else if (calcString.equals(2)) { + //scientific calculator } - else { - Console.println("New Value is:" + f.divide(i, i1)); - } - } else if (op.equals("^y")) { - Double i1 = Console.getDoubleInput("Please next number:"); - Console.println("New Value is:" + f.exponent(i, i1)); - - } else if (op.equals("^2")) { - Console.println("New Value is:" + f.square(i)); - } else if (op.equals("sqrt")) { - Console.println("New Value is:" + f.root(i)); - } else if (op.equals("inverse")) { - Console.println("New Value is:" + f.inverse(i)); - } else if (op.equals("invert")) { - Console.println("New Value is:" + f.invert(i)); - } else if (op.equals("c")) { - Console.println("New Value is:" + f.clear()); - } else if (op.equals("end")) - { - check = false; - } - else { - Console.println("Err"); + } catch (Exception e) { + Console.println("Wrong input"); } + } while (r == 1) ; - //Scanner username = new Scanner(System.in); - //String user = username.nextLine(); - //System.out.print("Hello " + user + " !"); - - - //Double i = Console.getDoubleInput("Enter a number"); - //Scanner number = new Scanner(System.in); - //int - - //String s = Console.getStringInput("Enter a string"); - //Double i = Console.getDoubleInput("Enter an Double"); - //Double d = Console.getDoubleInput("Enter a double."); - - //Console.println("Hello" + s); - //Console.println("The user input %s as a Double", i); - //Console.println("The user input %s as a d", d); - } } } - diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java index 280dcc71..85663ad7 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java @@ -7,12 +7,14 @@ public class SciFeatures { + public SciFeatures(){ } private String unitsMode; private String displayMode; - private Stack s; + + public double p; public void setDisplayMode(String a) { this.displayMode = a; @@ -40,17 +42,15 @@ public void switchDisplayMode(String mode) { } public void storeMemory(double a) { - s.push(a); + this.p = a; } public void clearMemory() { - if (s.empty() == false) { - s.pop(); - } + this.p = Double.NaN; } public double memoryRecall(){ - return (double) s.peek(); + return this.p; } public double sine(double a) { diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/FeaturesTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/FeaturesTest.java new file mode 100644 index 00000000..222c05a2 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/FeaturesTest.java @@ -0,0 +1,108 @@ +package com.zipcodewilmington.scientific_calculator; + +import com.zipcodewilmington.scientificcalculator.Features; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class FeaturesTest { + Features test = new Features(); + + @Test + public void addTest1() { + assertEquals(5, test.add(2, 3), 0.01); + } + + @Test + public void addTest2() { + assertEquals(5.5, test.add(3, 2.5), 0.01); + } + + @Test + public void subTest1() { + assertEquals(10, test.subtract(13, 3), 0.01); + } + + @Test + public void subTest2() { + assertEquals(2.2, test.subtract(5.2, 3), 0.01); + } + + @Test + public void multTest1() { + assertEquals(12, test.multiply(6.0, 2), 0.01); + } + + @Test + public void multiTest2() { + assertEquals(100, test.multiply(1, 100), 0.01); + } + + @Test + public void divTest1() { + assertEquals(8, test.divide(32, 4), 0.01); + } + + @Test + public void divTest2(){ + assertEquals(5, test.divide(40, 8), 0.01); + } + @Test + public void squareTest1(){ + assertEquals(25, test.square( 5), 0.01); + } + @Test + public void squareTest2(){ + assertEquals(144, test.square( 12),0.01); + } + @Test + public void rootTest1(){ + assertEquals(8, test.root( 64), 0.01); + } + @Test + public void rootTest2(){ + assertEquals(2, test.root( 4), 0.01); + } + @Test + public void exponentTest1(){ + assertEquals(32, test.exponent(2, 5), 0.01); + } + @Test + public void exponentTest2(){ + assertEquals(282475249, test.exponent(7, 10), 0.01); + } + @Test + public void invertTest1(){ + assertEquals(10, + test.invert( -10), + 0.01); + } + @Test + public void invertTest2(){ + assertEquals(-20, + test.invert( 20), + 0.01); + } + @Test + public void clearTest1(){ + assertEquals(0, + test.clear(), + 0.01); + } + @Test + public void clearTest2(){ + assertEquals(0, + test.clear(), + 0.01); + } + @Test + public void inverseTest1(){ + assertEquals(0.25, test.inverse( 4), 0.01); + } + + @Test + public void inverseTest2(){ + assertEquals(.33, test.inverse(3), 0.01); + } + +} diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java index 9d9e30b5..0a41d54f 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java @@ -41,7 +41,7 @@ public void switchTest4(){ @Test public void memoryTest(){ test.storeMemory(2); - assertEquals(2, test.memoryRecall()); + assertEquals(2, test.memoryRecall(), 0.01); } } From 36bf07b61382d07b7bb66d28a294e5faa70bb7e7 Mon Sep 17 00:00:00 2001 From: Chris Farmer Date: Sun, 9 Feb 2020 00:43:30 -0500 Subject: [PATCH 10/17] this project will kill me --- .../scientificcalculator/MainApplication.java | 309 +++++++++++++++--- .../scientificcalculator/SciFeatures.java | 12 +- 2 files changed, 269 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index fd084bd1..843bd7ff 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -11,6 +11,8 @@ public static void main(String[] args) { Features f = new Features(); SciFeatures sf = new SciFeatures(); + sf.displayMode = "decimal"; + sf.unitsMode = "Degrees"; Console.println("Welcome to my calculator!"); @@ -20,64 +22,279 @@ public static void main(String[] args) { int r = 1; do { try { - Double calcString = Console.getDoubleInput("Press 1 for base calculator and 2 for scientific calculator. "); + Double calcDouble = Console.getDoubleInput("Press 1 for base calculator and 2 for scientific calculator. "); - if (calcString == 1) { + if (calcDouble == 1) { Console.println("Current number is :" + display); - Double i = Console.getDoubleInput("Please enter another number if you want:"); + //Double i = Console.getDoubleInput("Please enter another number if you want:"); boolean check = true; while (check) { - String op = Console.getOperationInput("Enter an operation : +, - , *, /, ^2, ^y, inverse, sqrt, invert, c, end : "); - - - if (op.equals("+")) { - Double i1 = Console.getDoubleInput("Please next number:"); - Console.println("New Value is: " + f.add(i, i1)); - i = f.add(i, i1); - } else if (op.equals("-")) { - Double i1 = Console.getDoubleInput("Please next number:"); - Console.println("New Value is:" + f.subtract(i, i1)); - } else if (op.equals("*")) { - Double i1 = Console.getDoubleInput("Please next number:"); - Console.println("New Value is:" + f.multiply(i, i1)); - } else if (op.equals("/")) { - Double i1 = Console.getDoubleInput("Please next number:"); - if (i1 == 0) { - Console.println("Err"); - } else { - Console.println("New Value is:" + f.divide(i, i1)); + do { + try { + r = 1; + Double i = Console.getDoubleInput("Please enter another number if you want:"); + String op = Console.getOperationInput("Enter an operation : +, - , *, /, ^2, ^y, inverse, sqrt, invert, c, end : "); + if (op.equals("+")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + Console.println("New Value is: " + f.add(i, i1)); + i = f.add(i, i1); + } else if (op.equals("-")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + Console.println("New Value is: " + f.subtract(i, i1)); + } else if (op.equals("*")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + Console.println("New Value is: " + f.multiply(i, i1)); + } else if (op.equals("/")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + if (i1 == 0) { + Console.println("Err"); + } else { + Console.println("New Value is: " + f.divide(i, i1)); + } + } else if (op.equals("^y")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + Console.println("New Value is: " + f.exponent(i, i1)); + + } else if (op.equals("^2")) { + Console.println("New Value is: " + f.square(i)); + } else if (op.equals("sqrt")) { + if (i < 0) { + Console.println("Err"); + } else { + Console.println("New Value is: " + f.root(i)); + } + } else if (op.equals("inverse")) { + if (i == 0) { + Console.println("Err"); + } else { + Console.println("New Value is: " + f.inverse(i)); + } + } else if (op.equals("invert")) { + Console.println("New Value is: " + f.invert(i)); + } else if (op.equals("c")) { + Console.println("New Value is: " + f.clear()); + i = 0.0; + } else if (op.equals("end")) { + check = false; + r = 2; + } else { + Console.println("Err"); + } + + } catch (Exception e) { + + } + } while (r == 1); + } + } else if (calcDouble == 2) { + Console.println("The current modes are decimal and Degrees."); + Console.println("Current number is :" + display); + + //Double i = Console.getDoubleInput("Please enter another number if you want:"); + + boolean check = true; + while (check) { + do { + try { + r = 1; + Double i = Console.getDoubleInput("Please enter another number if you want:"); + String op = Console.getOperationInput("Enter an operation : +, - , *, /, ^2, ^y, inverse, sqrt, invert, display(), display, M+, MC, MRC, Sine, Cosine,\n" + + " Tangent, invSine, invCosine, invTangent, units(), units, log, 10^x, Ln, e^x, !, c, end : "); + if (op.equals("+")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + Console.println("New Value is: " + f.add(i, i1)); + i = f.add(i, i1); + } else if (op.equals("-")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + Console.println("New Value is: " + f.subtract(i, i1)); + i = f.subtract(i,i1); + } else if (op.equals("*")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + Console.println("New Value is: " + f.multiply(i, i1)); + i = f.multiply(i,i1); + } else if (op.equals("/")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + if (i1 == 0) { + Console.println("Err"); + } else { + Console.println("New Value is: " + f.divide(i, i1)); + i = f.divide(i,i1); + } + } else if (op.equals("^y")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + Console.println("New Value is: " + f.exponent(i, i1)); + i = f.exponent(i,i1); + } else if (op.equals("^2")) { + Console.println("New Value is: " + f.square(i)); + i = f.square(i) + } else if (op.equals("sqrt")) { + if (i < 0) { + Console.println("Err"); + } else { + Console.println("New Value is: " + f.root(i)); + i = f.root(i); + } + } else if (op.equals("inverse")) { + if (i == 0) { + Console.println("Err"); + } else { + Console.println("New Value is: " + f.inverse(i)); + i = f.inverse(i); + } + } else if (op.equals("invert")) { + Console.println("New Value is: " + f.invert(i)); + i = f.invert(i); + } else if (op.equals("c")) { + Console.println("New Value is: " + f.clear()); + i = 0.0; + } else if (op.equals("end")) { + check = false; + r = 2; + } else if (op.equals("switch()")) { + int t = 1; + do{ + try{ + String imp = Console.getStringInput("Type binary, octal, decimal, hexadecimal"); + if (imp.equalsIgnoreCase("binary")){ + sf.switchDisplayMode("binary"); + } + else if (imp.equalsIgnoreCase("octal")){ + sf.switchDisplayMode("octal"); + } + else if (imp.equalsIgnoreCase("decimal")){ + sf.switchDisplayMode("decimal"); + } + else if (imp.equalsIgnoreCase("hexadecimal")){ + sf.switchDisplayMode("hexadecimal"); + } + t++; + } catch (Exception e){ + Console.println("Why are you the way that you are?"); + } + } while (t == 1); + } + else if (op.equals("switch")){ + sf.switchDisplayMode(); + } + else if (op.equals("M+")){ + sf.storeMemory(i); + } + else if (op.equals("MC")){ + sf.clearMemory(); + } + else if (op.equals("MRC")){ + Console.println("" + sf.memoryRecall()); + i = sf.memoryRecall(); + } + else if (op.equals("Sine")){ + if (sf.unitsMode == "Degrees"){ + Console.println("New Value is: " +sf.sine(i)); + i = sf.sine(i); + } + else { + Console.println("New Value is: " +sf.sine(Math.toRadians(i))); + i = sf.sine(Math.toRadians(i)); + } + } + else if (op.equals("Cosine")){ + if (sf.unitsMode == "Degrees"){ + Console.println("New Value is: " +sf.cosine(i)); + i = sf.cosine(i); + } + else { + Console.println("New Value is: " +sf.cosine(Math.toRadians(i))); + i = sf.cosine(Math.toRadians(i)); + } + } + else if (op.equals("Tangent")){ + if (sf.unitsMode == "Degrees"){ + Console.println("New Value is: " +sf.tangent(i)); + i = sf.tangent(i); + } + else { + Console.println("New Value is: " +sf.tangent(Math.toRadians(i))); + i = sf.tangent(Math.toRadians(i)); + } + } + else if (op.equals("invSine")){ + if (sf.unitsMode == "Degrees"){ + Console.println("New Value is: " +sf.sineInverse(i)); + i = sf.sineInverse(i); + } + else { + Console.println("New Value is: " +sf.sineInverse(Math.toRadians(i))); + i = sf.sineInverse(Math.toRadians(i)); + } + } + else if (op.equals("invCosine")){ + if (sf.unitsMode == "Degrees"){ + Console.println("New Value is: " +sf.cosineInverse(i)); + i = sf.cosineInverse(i); + } + else { + Console.println("New Value is: " +sf.cosineInverse(Math.toRadians(i))); + i = sf.cosineInverse(Math.toRadians(i)); + } + } + else if (op.equals("invTangent")){ + if (sf.unitsMode == "Degrees"){ + Console.println("New Value is: " +sf.tangentInverse(i)); + i = sf.tangentInverse(i); + } + else { + Console.println("New Value is: " +sf.tangentInverse(Math.toRadians(i)); + i = sf.tangentInverse(Math.toRadians(i)); + } + } + else if (op.equals("log")){ + if (i <= 0){ + Console.println("Err"); + } + else { + Console.println("New Value is: " + sf.logarithm(i)); + i = sf.logarithm(i); + } + } + else if (op.equals("10^x")){ + Console.println("New Value is: " + sf.inverseLog(i) ); + i = sf.inverseLog(i); + } + else if (op.equals("Ln")){ + if (i <= 0){ + Console.println("Err"); + } + else { + Console.println("New Value is: " + sf.naturalLog(i)); + i = sf.naturalLog(i); + } + } + else if (op.equals("e^x")){ + Console.println("New Value is: " + sf.inverseNaturalLog(i) ); + i = sf.inverseNaturalLog(i); + } + else if (op.equals("!")){ + int factor = Math.toIntExact(Math.round(i)); + + + Console.println("New Value is: " + sf.factorial(factor)); + i = Double.valueOf(sf.factorial(factor)); + } + + else { + Console.println("Err"); + } + + } catch (Exception e) { + } - } else if (op.equals("^y")) { - Double i1 = Console.getDoubleInput("Please next number:"); - Console.println("New Value is:" + f.exponent(i, i1)); - - } else if (op.equals("^2")) { - Console.println("New Value is:" + f.square(i)); - } else if (op.equals("sqrt")) { - Console.println("New Value is:" + f.root(i)); - } else if (op.equals("inverse")) { - Console.println("New Value is:" + f.inverse(i)); - } else if (op.equals("invert")) { - Console.println("New Value is:" + f.invert(i)); - } else if (op.equals("c")) { - Console.println("New Value is:" + f.clear()); - } else if (op.equals("end")) { - check = false; - } else { - Console.println("Err"); - } + } while (r == 1); } - } else if (calcString.equals(2)) { - //scientific calculator } } catch (Exception e) { Console.println("Wrong input"); } } while (r == 1) ; - - - } } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java index 85663ad7..057c579a 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SciFeatures.java @@ -11,8 +11,8 @@ public class SciFeatures { public SciFeatures(){ } - private String unitsMode; - private String displayMode; + public String unitsMode; + public String displayMode; public double p; @@ -77,8 +77,8 @@ public double tangentInverse(double a) { return atan(a); } - public double toRadian(double a){ - return toRadians(a); + public double toDegree(double a){ + return toDegrees(a); } public void switchUnitsMode() { @@ -99,7 +99,7 @@ public double logarithm(double a) { } public double inverseLog(double a) { - return exp(a); + return Math.pow(10, a); } public double naturalLog(double a) { @@ -107,7 +107,7 @@ public double naturalLog(double a) { } public double inverseNaturalLog(double a){ - return Math.pow(10, a); + return exp(a); } From 3976d5258c507de2c58ac087e0af60a5699cc9df Mon Sep 17 00:00:00 2001 From: Chris Farmer Date: Sun, 9 Feb 2020 09:39:58 -0500 Subject: [PATCH 11/17] almost done adding bonus features and fixing main --- .../scientificcalculator/MainApplication.java | 21 ++++++++++++------- .../scientificcalculator/Shapes.java | 18 ++++++++++++++++ .../scientific_calculator/ShapesTest.java | 4 ++++ 3 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/Shapes.java create mode 100644 src/test/java/com/zipcodewilmington/scientific_calculator/ShapesTest.java diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 843bd7ff..d524fd75 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -22,7 +22,7 @@ public static void main(String[] args) { int r = 1; do { try { - Double calcDouble = Console.getDoubleInput("Press 1 for base calculator and 2 for scientific calculator. "); + Double calcDouble = Console.getDoubleInput("Press 1 for base calculator, 2 for scientific calculator, or 3 for shapes!"); if (calcDouble == 1) { Console.println("Current number is :" + display); @@ -128,7 +128,7 @@ public static void main(String[] args) { i = f.exponent(i,i1); } else if (op.equals("^2")) { Console.println("New Value is: " + f.square(i)); - i = f.square(i) + i = f.square(i); } else if (op.equals("sqrt")) { if (i < 0) { Console.println("Err"); @@ -229,13 +229,18 @@ else if (op.equals("invSine")){ } } else if (op.equals("invCosine")){ - if (sf.unitsMode == "Degrees"){ - Console.println("New Value is: " +sf.cosineInverse(i)); - i = sf.cosineInverse(i); + if (i < -1 || i > 1){ + Console.println("Err"); } - else { - Console.println("New Value is: " +sf.cosineInverse(Math.toRadians(i))); - i = sf.cosineInverse(Math.toRadians(i)); + else{ + if (sf.unitsMode == "Degrees") { + Console.println("New Value is: " + sf.cosineInverse(i)); + i = sf.cosineInverse(i); + } else { + Console.println("New Value is: " + sf.cosineInverse(Math.toRadians(i))); + i = sf.cosineInverse(Math.toRadians(i)); + } + } } else if (op.equals("invTangent")){ diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Shapes.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Shapes.java new file mode 100644 index 00000000..216f37ed --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Shapes.java @@ -0,0 +1,18 @@ +package com.zipcodewilmington.scientificcalculator; + +public class Shapes { + + public Shapes(){} + + //circle + + //triangle + + //quad + + //box + + //cylinder + + // pyramid +} diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/ShapesTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/ShapesTest.java new file mode 100644 index 00000000..7cf03ebf --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/ShapesTest.java @@ -0,0 +1,4 @@ +package com.zipcodewilmington.scientific_calculator; + +public class ShapesTest { +} From 6c6e438960e4ba8daeeedb46c6a67931ae3179a5 Mon Sep 17 00:00:00 2001 From: Chris Farmer Date: Sun, 9 Feb 2020 11:19:43 -0500 Subject: [PATCH 12/17] almost done tests then fix switch modes --- pom.xml | 18 ++ .../scientificcalculator/Console.java | 2 +- .../scientificcalculator/MainApplication.java | 222 ++++++++++-------- .../scientificcalculator/Shapes.java | 14 +- .../SciFeaturesTest.java | 87 +++++++ .../scientific_calculator/ShapesTest.java | 36 +++ 6 files changed, 280 insertions(+), 99 deletions(-) diff --git a/pom.xml b/pom.xml index d8cd763e..42867636 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,18 @@ com.zipcodewilmington scientific_calculator 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + junit @@ -14,6 +26,12 @@ 4.12 test + + org.junit.jupiter + junit-jupiter + RELEASE + test + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index 8ffdebd5..04363c12 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -20,7 +20,7 @@ public static String getStringInput(String prompt) Scanner username = new Scanner(System.in); println (prompt); String user = username.nextLine(); - System.out.println("Hello " + user + " !"); + System.out.println("Hello " + user + "!"); return user; } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index d524fd75..557bf49a 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -8,12 +8,13 @@ public class MainApplication { public static void main(String[] args) { - + Shapes shapes = new Shapes(); Features f = new Features(); SciFeatures sf = new SciFeatures(); sf.displayMode = "decimal"; sf.unitsMode = "Degrees"; + Console.println("Welcome to my calculator!"); String s = Console.getStringInput("Please enter your name?"); @@ -25,7 +26,7 @@ public static void main(String[] args) { Double calcDouble = Console.getDoubleInput("Press 1 for base calculator, 2 for scientific calculator, or 3 for shapes!"); if (calcDouble == 1) { - Console.println("Current number is :" + display); + Console.println("Current number is: " + display); //Double i = Console.getDoubleInput("Please enter another number if you want:"); @@ -101,7 +102,7 @@ public static void main(String[] args) { r = 1; Double i = Console.getDoubleInput("Please enter another number if you want:"); String op = Console.getOperationInput("Enter an operation : +, - , *, /, ^2, ^y, inverse, sqrt, invert, display(), display, M+, MC, MRC, Sine, Cosine,\n" + - " Tangent, invSine, invCosine, invTangent, units(), units, log, 10^x, Ln, e^x, !, c, end : "); + " Tangent, invSine, invCosine, invTangent, units(), units, log, 10^x, Ln, e^x, !, c, end(to exit) : "); if (op.equals("+")) { Double i1 = Console.getDoubleInput("Please enter next number:"); Console.println("New Value is: " + f.add(i, i1)); @@ -109,23 +110,23 @@ public static void main(String[] args) { } else if (op.equals("-")) { Double i1 = Console.getDoubleInput("Please enter next number:"); Console.println("New Value is: " + f.subtract(i, i1)); - i = f.subtract(i,i1); + i = f.subtract(i, i1); } else if (op.equals("*")) { Double i1 = Console.getDoubleInput("Please enter next number:"); Console.println("New Value is: " + f.multiply(i, i1)); - i = f.multiply(i,i1); + i = f.multiply(i, i1); } else if (op.equals("/")) { Double i1 = Console.getDoubleInput("Please enter next number:"); if (i1 == 0) { Console.println("Err"); } else { Console.println("New Value is: " + f.divide(i, i1)); - i = f.divide(i,i1); + i = f.divide(i, i1); } } else if (op.equals("^y")) { Double i1 = Console.getDoubleInput("Please enter next number:"); Console.println("New Value is: " + f.exponent(i, i1)); - i = f.exponent(i,i1); + i = f.exponent(i, i1); } else if (op.equals("^2")) { Console.println("New Value is: " + f.square(i)); i = f.square(i); @@ -154,85 +155,72 @@ public static void main(String[] args) { r = 2; } else if (op.equals("switch()")) { int t = 1; - do{ - try{ - String imp = Console.getStringInput("Type binary, octal, decimal, hexadecimal"); - if (imp.equalsIgnoreCase("binary")){ + do { + try { + String imp = Console.getOperationInput("Type binary, octal, decimal, hexadecimal"); + if (imp.equalsIgnoreCase("binary")) { sf.switchDisplayMode("binary"); - } - else if (imp.equalsIgnoreCase("octal")){ + } else if (imp.equalsIgnoreCase("octal")) { sf.switchDisplayMode("octal"); - } - else if (imp.equalsIgnoreCase("decimal")){ + } else if (imp.equalsIgnoreCase("decimal")) { sf.switchDisplayMode("decimal"); - } - else if (imp.equalsIgnoreCase("hexadecimal")){ + } else if (imp.equalsIgnoreCase("hexadecimal")) { sf.switchDisplayMode("hexadecimal"); } t++; - } catch (Exception e){ + } catch (Exception e) { Console.println("Why are you the way that you are?"); } } while (t == 1); - } - else if (op.equals("switch")){ + } else if (op.equals("switch")) { sf.switchDisplayMode(); - } - else if (op.equals("M+")){ + } else if (op.equals("M+")) { sf.storeMemory(i); - } - else if (op.equals("MC")){ + } else if (op.equals("MC")) { sf.clearMemory(); - } - else if (op.equals("MRC")){ + } else if (op.equals("MRC")) { Console.println("" + sf.memoryRecall()); i = sf.memoryRecall(); - } - else if (op.equals("Sine")){ - if (sf.unitsMode == "Degrees"){ - Console.println("New Value is: " +sf.sine(i)); + } else if (op.equals("Sine")) { + if (sf.unitsMode == "Degrees") { + Console.println("New Value is: " + sf.sine(i)); i = sf.sine(i); - } - else { - Console.println("New Value is: " +sf.sine(Math.toRadians(i))); + } else { + Console.println("New Value is: " + sf.sine(Math.toRadians(i))); i = sf.sine(Math.toRadians(i)); } - } - else if (op.equals("Cosine")){ - if (sf.unitsMode == "Degrees"){ - Console.println("New Value is: " +sf.cosine(i)); + } else if (op.equals("Cosine")) { + if (sf.unitsMode == "Degrees") { + Console.println("New Value is: " + sf.cosine(i)); i = sf.cosine(i); - } - else { - Console.println("New Value is: " +sf.cosine(Math.toRadians(i))); + } else { + Console.println("New Value is: " + sf.cosine(Math.toRadians(i))); i = sf.cosine(Math.toRadians(i)); } - } - else if (op.equals("Tangent")){ - if (sf.unitsMode == "Degrees"){ - Console.println("New Value is: " +sf.tangent(i)); + } else if (op.equals("Tangent")) { + if (sf.unitsMode == "Degrees") { + Console.println("New Value is: " + sf.tangent(i)); i = sf.tangent(i); - } - else { - Console.println("New Value is: " +sf.tangent(Math.toRadians(i))); + } else { + Console.println("New Value is: " + sf.tangent(Math.toRadians(i))); i = sf.tangent(Math.toRadians(i)); } - } - else if (op.equals("invSine")){ - if (sf.unitsMode == "Degrees"){ - Console.println("New Value is: " +sf.sineInverse(i)); - i = sf.sineInverse(i); - } - else { - Console.println("New Value is: " +sf.sineInverse(Math.toRadians(i))); - i = sf.sineInverse(Math.toRadians(i)); - } - } - else if (op.equals("invCosine")){ - if (i < -1 || i > 1){ + } else if (op.equals("invSine")) { + if (i < -1 || i > 1) { Console.println("Err"); + } else { + if (sf.unitsMode == "Degrees") { + Console.println("New Value is: " + sf.sineInverse(i)); + i = sf.sineInverse(i); + } else { + Console.println("New Value is: " + sf.sineInverse(Math.toRadians(i))); + i = sf.sineInverse(Math.toRadians(i)); + } } - else{ + } else if (op.equals("invCosine")) { + if (i < -1 || i > 1) { + Console.println("Err"); + } else { if (sf.unitsMode == "Degrees") { Console.println("New Value is: " + sf.cosineInverse(i)); i = sf.cosineInverse(i); @@ -242,52 +230,39 @@ else if (op.equals("invCosine")){ } } - } - else if (op.equals("invTangent")){ - if (sf.unitsMode == "Degrees"){ - Console.println("New Value is: " +sf.tangentInverse(i)); + } else if (op.equals("invTangent")) { + if (sf.unitsMode == "Degrees") { + Console.println("New Value is: " + sf.tangentInverse(i)); i = sf.tangentInverse(i); - } - else { - Console.println("New Value is: " +sf.tangentInverse(Math.toRadians(i)); + } else { + Console.println("New Value is: " + sf.tangentInverse(Math.toRadians(i))); i = sf.tangentInverse(Math.toRadians(i)); } - } - else if (op.equals("log")){ - if (i <= 0){ + } else if (op.equals("log")) { + if (i <= 0) { Console.println("Err"); - } - else { + } else { Console.println("New Value is: " + sf.logarithm(i)); i = sf.logarithm(i); } - } - else if (op.equals("10^x")){ - Console.println("New Value is: " + sf.inverseLog(i) ); + } else if (op.equals("10^x")) { + Console.println("New Value is: " + sf.inverseLog(i)); i = sf.inverseLog(i); - } - else if (op.equals("Ln")){ - if (i <= 0){ + } else if (op.equals("Ln")) { + if (i <= 0) { Console.println("Err"); - } - else { + } else { Console.println("New Value is: " + sf.naturalLog(i)); i = sf.naturalLog(i); } - } - else if (op.equals("e^x")){ - Console.println("New Value is: " + sf.inverseNaturalLog(i) ); + } else if (op.equals("e^x")) { + Console.println("New Value is: " + sf.inverseNaturalLog(i)); i = sf.inverseNaturalLog(i); - } - else if (op.equals("!")){ + } else if (op.equals("!")) { int factor = Math.toIntExact(Math.round(i)); - - Console.println("New Value is: " + sf.factorial(factor)); i = Double.valueOf(sf.factorial(factor)); - } - - else { + } else { Console.println("Err"); } @@ -296,9 +271,70 @@ else if (op.equals("!")){ } } while (r == 1); } + } else if (calcDouble == 3) { + boolean check = true; + while (check) { + do { + try { + r = 1; + String op = Console.getOperationInput("Enter a shape you wish to work with: quad, circle, triangle or end(to exit)"); + if (op.equalsIgnoreCase("quad")){ + String info = Console.getOperationInput("Press r to return or continue to quadrilateral area with any key."); + if (info.equalsIgnoreCase("r")){ + } + else { + double w = Console.getDoubleInput("Enter the width"); + double l = Console.getDoubleInput("Enter the length"); + if(w < 0 || l < 0){ + Console.println("Err"); + } + else{ + Console.println("The area of your quadrilateral is: " + shapes.quadArea(w,l)); + } + } + } + else if (op.equalsIgnoreCase("triangle")){ + String info1 = Console.getOperationInput("Press r to return or continue to triangle area with any key."); + if (info1.equalsIgnoreCase("r")){ + } + else { + double w = Console.getDoubleInput("Enter the width"); + double h = Console.getDoubleInput("Enter the height"); + if(w < 0 || h < 0){ + Console.println("Err"); + } + else{ + Console.println("The area of your triangle is: " + shapes.triangleArea(w, h)); + } + } + } + else if (op.equalsIgnoreCase("circle")){ + String info2 = Console.getOperationInput(("Press r to return or continue to circle area with any key.")); + if (info2.equalsIgnoreCase("r")){ + } + else { + double radius = Console.getDoubleInput("Enter the radius"); + if (radius < 0) { + Console.println("Err"); + } + else { + Console.println("The area of your circle is "+ shapes.circleArea(radius)); + } + } + } + else if (op.equals("end")) { + check = false; + r = 2; + } + } + catch (Exception e) { + Console.println("Err"); + } + } while (r == 1); + } } - } catch (Exception e) { - Console.println("Wrong input"); + }catch (Exception e) { + Console.println("Err"); } } while (r == 1) ; } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Shapes.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Shapes.java index 216f37ed..ef2edefb 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Shapes.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Shapes.java @@ -5,14 +5,18 @@ public class Shapes { public Shapes(){} //circle + public double circleArea(double r){ + return Math.PI * Math.pow(r, 2); + } //triangle + public double triangleArea(double w, double h){ + return 0.5 * w * h; + } //quad + public double quadArea(double w, double l){ + return w * l; + } - //box - - //cylinder - - // pyramid } diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java index 0a41d54f..4db6520d 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java @@ -44,4 +44,91 @@ public void memoryTest(){ assertEquals(2, test.memoryRecall(), 0.01); } + @Test + public void sinTest(){ + assertEquals(Math.sin(90), test.sine(90), 0.01); + } + @Test + public void cosTest(){ + assertEquals(Math.cos(90), test.cosine(90), 0.01); + } + @Test + public void tanTest(){ + assertEquals(Math.tan(45), test.tangent(45), 0.01); + } + @Test + public void invSinTest(){ + assertEquals(Math.asin(15), test.sineInverse(15), 0.01); + } + @Test + public void invCosTest(){ + assertEquals(Math.acos(15), test.cosineInverse(15), 0.01); + } + @Test + public void invTanTest(){ + assertEquals(Math.atan(15), test.tangentInverse(15), 0.01); + } + @Test + public void sinTest1(){ + assertEquals(Math.sin(45), test.sine(45), 0.01); + } + @Test + public void cosTest1(){ + assertEquals(Math.cos(45), test.cosine(45), 0.01); + } + @Test + public void tanTest1(){ + assertEquals(Math.tan(15), test.tangent(15), 0.01); + } + @Test + public void invSinTest1(){ + assertEquals(Math.asin(30), test.sineInverse(30), 0.01); + } + @Test + public void invCosTest1(){ + assertEquals(Math.acos(30), test.cosineInverse(30), 0.01); + } + @Test + public void invTanTest1(){ + assertEquals(Math.atan(30), test.tangentInverse(30), 0.01); + } + @Test + public void unitModeTest(){ + test.unitsMode = "Degrees"; + test.switchUnitsMode(); + assertEquals("Radians", test.unitsMode); + } + @Test + public void unitModeTest1(){ + test.unitsMode = "Radians"; + test.switchUnitsMode(); + assertEquals("Degrees", test.unitsMode); + } + @Test + public void unitModeInpTest(){ + test.switchUnitsMode("Degrees"); + assertEquals("Degrees", test.unitsMode); + } + @Test + public void unitModeInpTest1(){ + test.switchUnitsMode("Radians"); + assertEquals("Radians", test.unitsMode); + } + @Test + public void logTest(){ + assertEquals(3, test.logarithm(1000), 0.01); + } + @Test + public void logTest1(){ + assertEquals(4, test.logarithm(10000), 0.01); + } + @Test + public void invLogTest(){ + assertEquals(10, test.inverseLog(1), 0.01); + } + @Test + public void invLogTest1(){ + assertEquals(100, test.inverseLog(2), 0.01); + } + } diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/ShapesTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/ShapesTest.java index 7cf03ebf..adbe6d5a 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/ShapesTest.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/ShapesTest.java @@ -1,4 +1,40 @@ package com.zipcodewilmington.scientific_calculator; +import com.zipcodewilmington.scientificcalculator.Shapes; +import org.junit.Test; + + +import static org.junit.Assert.assertEquals; + public class ShapesTest { + Shapes s = new Shapes(); + public ShapesTest(){} + //quad + @Test + public void quadTest(){ + assertEquals(4, s.quadArea(2,2), 0.01); + } + @Test + public void quadTest1(){ + assertEquals(10, s.quadArea(10, 1), 0.01); + } + + //triangle + @Test + public void triTest1(){ + assertEquals(10, s.triangleArea(2,10), 0.01); + } + @Test + public void triTest2(){ + assertEquals(12, s.triangleArea(3, 8), 0.01); + } + //circle + @Test + public void cirTest1(){ + assertEquals(12.56, s.circleArea(2), 0.01); + } + @Test + public void cirTest2(){ + assertEquals(28.27, s.circleArea(3), 0.01); + } } From 3852ec6c5a11aa0c2567e85007ec2ace10dcd8f4 Mon Sep 17 00:00:00 2001 From: Chris Farmer Date: Sun, 9 Feb 2020 11:25:13 -0500 Subject: [PATCH 13/17] tests are done --- .../SciFeaturesTest.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java index 4db6520d..e8d44154 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/SciFeaturesTest.java @@ -130,5 +130,28 @@ public void invLogTest(){ public void invLogTest1(){ assertEquals(100, test.inverseLog(2), 0.01); } - + @Test + public void natLogTest(){ + assertEquals(Math.log(3), test.naturalLog(3), 0.01); + } + @Test + public void natLogTest1(){ + assertEquals(Math.log(10), test.naturalLog(10), 0.01); + } + @Test + public void invNatLogTest(){ + assertEquals(Math.exp(5), test.inverseNaturalLog(5), 0.01); + } + @Test + public void invNatLogTest1(){ + assertEquals(Math.exp(2.5), test.inverseNaturalLog(2.5), 0.01); + } + @Test + public void factorialTest(){ + assertEquals(24, test.factorial(4), 0.01); + } + @Test + public void factorialTest1(){ + assertEquals(5040, test.factorial(7), 0.01); + } } From 955ae919fed9657421796a56ca7aae4fd9cc1824 Mon Sep 17 00:00:00 2001 From: Chris Farmer Date: Sun, 9 Feb 2020 13:28:00 -0500 Subject: [PATCH 14/17] almost done with main --- .../scientificcalculator/MainApplication.java | 803 +++++++++++------- 1 file changed, 519 insertions(+), 284 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 557bf49a..b6528a28 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -2,6 +2,8 @@ import java.util.Scanner; +import static java.lang.Integer.*; + /** * Created by leon on 2/9/18. */ @@ -18,324 +20,557 @@ public static void main(String[] args) { Console.println("Welcome to my calculator!"); String s = Console.getStringInput("Please enter your name?"); + boolean eternal = true; + while (eternal) { + int display = 0; + int r = 1; + do { + try { + Double calcDouble = Console.getDoubleInput("Press 1 for base calculator, 2 for scientific calculator, or 3 for shapes!"); - int display = 0; - int r = 1; - do { - try { - Double calcDouble = Console.getDoubleInput("Press 1 for base calculator, 2 for scientific calculator, or 3 for shapes!"); - - if (calcDouble == 1) { - Console.println("Current number is: " + display); + if (calcDouble == 1) { + Console.println("Current number is: " + display); - //Double i = Console.getDoubleInput("Please enter another number if you want:"); + //Double i = Console.getDoubleInput("Please enter another number if you want:"); - boolean check = true; - while (check) { - do { - try { - r = 1; - Double i = Console.getDoubleInput("Please enter another number if you want:"); - String op = Console.getOperationInput("Enter an operation : +, - , *, /, ^2, ^y, inverse, sqrt, invert, c, end : "); - if (op.equals("+")) { - Double i1 = Console.getDoubleInput("Please enter next number:"); - Console.println("New Value is: " + f.add(i, i1)); - i = f.add(i, i1); - } else if (op.equals("-")) { - Double i1 = Console.getDoubleInput("Please enter next number:"); - Console.println("New Value is: " + f.subtract(i, i1)); - } else if (op.equals("*")) { - Double i1 = Console.getDoubleInput("Please enter next number:"); - Console.println("New Value is: " + f.multiply(i, i1)); - } else if (op.equals("/")) { - Double i1 = Console.getDoubleInput("Please enter next number:"); - if (i1 == 0) { - Console.println("Err"); - } else { - Console.println("New Value is: " + f.divide(i, i1)); - } - } else if (op.equals("^y")) { - Double i1 = Console.getDoubleInput("Please enter next number:"); - Console.println("New Value is: " + f.exponent(i, i1)); + boolean check = true; + while (check) { + do { + try { + r = 1; + Double i = Console.getDoubleInput("Please enter another number if you want:"); + String op = Console.getOperationInput("Enter an operation : +, - , *, /, ^2, ^y, inverse, sqrt, invert, c, end : "); + if (op.equals("+")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + Console.println("New Value is: " + f.add(i, i1)); + i = f.add(i, i1); + } else if (op.equals("-")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + Console.println("New Value is: " + f.subtract(i, i1)); + } else if (op.equals("*")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + Console.println("New Value is: " + f.multiply(i, i1)); + } else if (op.equals("/")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + if (i1 == 0) { + Console.println("Err"); + } else { + Console.println("New Value is: " + f.divide(i, i1)); + } + } else if (op.equals("^y")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + Console.println("New Value is: " + f.exponent(i, i1)); - } else if (op.equals("^2")) { - Console.println("New Value is: " + f.square(i)); - } else if (op.equals("sqrt")) { - if (i < 0) { - Console.println("Err"); + } else if (op.equals("^2")) { + Console.println("New Value is: " + f.square(i)); + } else if (op.equals("sqrt")) { + if (i < 0) { + Console.println("Err"); + } else { + Console.println("New Value is: " + f.root(i)); + } + } else if (op.equals("inverse")) { + if (i == 0) { + Console.println("Err"); + } else { + Console.println("New Value is: " + f.inverse(i)); + } + } else if (op.equals("invert")) { + Console.println("New Value is: " + f.invert(i)); + } else if (op.equals("c")) { + Console.println("New Value is: " + f.clear()); + i = 0.0; + } else if (op.equals("end")) { + check = false; + r = 2; } else { - Console.println("New Value is: " + f.root(i)); - } - } else if (op.equals("inverse")) { - if (i == 0) { Console.println("Err"); - } else { - Console.println("New Value is: " + f.inverse(i)); } - } else if (op.equals("invert")) { - Console.println("New Value is: " + f.invert(i)); - } else if (op.equals("c")) { - Console.println("New Value is: " + f.clear()); - i = 0.0; - } else if (op.equals("end")) { - check = false; - r = 2; - } else { - Console.println("Err"); - } - } catch (Exception e) { + } catch (Exception e) { - } - } while (r == 1); - } - } else if (calcDouble == 2) { - Console.println("The current modes are decimal and Degrees."); - Console.println("Current number is :" + display); + } + } while (r == 1); + } + } else if (calcDouble == 2) { + Console.println("The current modes are decimal and Degrees."); + Console.println("Current number is: " + display); - //Double i = Console.getDoubleInput("Please enter another number if you want:"); + //Double i = Console.getDoubleInput("Please enter another number if you want:"); - boolean check = true; - while (check) { - do { - try { - r = 1; - Double i = Console.getDoubleInput("Please enter another number if you want:"); - String op = Console.getOperationInput("Enter an operation : +, - , *, /, ^2, ^y, inverse, sqrt, invert, display(), display, M+, MC, MRC, Sine, Cosine,\n" + - " Tangent, invSine, invCosine, invTangent, units(), units, log, 10^x, Ln, e^x, !, c, end(to exit) : "); - if (op.equals("+")) { - Double i1 = Console.getDoubleInput("Please enter next number:"); - Console.println("New Value is: " + f.add(i, i1)); - i = f.add(i, i1); - } else if (op.equals("-")) { - Double i1 = Console.getDoubleInput("Please enter next number:"); - Console.println("New Value is: " + f.subtract(i, i1)); - i = f.subtract(i, i1); - } else if (op.equals("*")) { - Double i1 = Console.getDoubleInput("Please enter next number:"); - Console.println("New Value is: " + f.multiply(i, i1)); - i = f.multiply(i, i1); - } else if (op.equals("/")) { - Double i1 = Console.getDoubleInput("Please enter next number:"); - if (i1 == 0) { - Console.println("Err"); - } else { - Console.println("New Value is: " + f.divide(i, i1)); - i = f.divide(i, i1); - } - } else if (op.equals("^y")) { - Double i1 = Console.getDoubleInput("Please enter next number:"); - Console.println("New Value is: " + f.exponent(i, i1)); - i = f.exponent(i, i1); - } else if (op.equals("^2")) { - Console.println("New Value is: " + f.square(i)); - i = f.square(i); - } else if (op.equals("sqrt")) { - if (i < 0) { - Console.println("Err"); - } else { - Console.println("New Value is: " + f.root(i)); - i = f.root(i); - } - } else if (op.equals("inverse")) { - if (i == 0) { - Console.println("Err"); - } else { - Console.println("New Value is: " + f.inverse(i)); - i = f.inverse(i); - } - } else if (op.equals("invert")) { - Console.println("New Value is: " + f.invert(i)); - i = f.invert(i); - } else if (op.equals("c")) { - Console.println("New Value is: " + f.clear()); - i = 0.0; - } else if (op.equals("end")) { - check = false; - r = 2; - } else if (op.equals("switch()")) { - int t = 1; - do { - try { - String imp = Console.getOperationInput("Type binary, octal, decimal, hexadecimal"); - if (imp.equalsIgnoreCase("binary")) { - sf.switchDisplayMode("binary"); - } else if (imp.equalsIgnoreCase("octal")) { - sf.switchDisplayMode("octal"); - } else if (imp.equalsIgnoreCase("decimal")) { - sf.switchDisplayMode("decimal"); - } else if (imp.equalsIgnoreCase("hexadecimal")) { - sf.switchDisplayMode("hexadecimal"); + boolean check = true; + while (check) { + do { + try { + r = 1; + Double i = Console.getDoubleInput("Please enter another number if you want."); + String op = Console.getOperationInput("Enter an operation : +, - , *, /, ^2, ^y, inverse, sqrt, invert, display(), display, M+, MC, MRC, Sine, Cosine,\n" + + " Tangent, invSine, invCosine, invTangent, units(), units, log, 10^x, Ln, e^x, !, c, end(to exit) : "); + if (op.equals("+")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + if (sf.displayMode.equalsIgnoreCase("decimal")){ + Console.println("New Value is: " + f.add(i, i1)); + i = f.add(i, i1); + } + else if (sf.displayMode.equalsIgnoreCase("binary")){ + int j = (int) Math.round(f.add(i,i1)); + String str = toBinaryString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("hexadecimal")){ + int j = (int) Math.round(f.add(i,i1)); + String str = toHexString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("octal")){ + int j = (int) Math.round(f.add(i,i1)); + String str = toOctalString(j); + Console.println("New Value is: " + str); + } + } else if (op.equals("-")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + if (sf.displayMode.equalsIgnoreCase("decimal")){ + Console.println("New Value is: " + f.subtract(i, i1)); + i = f.subtract(i, i1); + } + else if (sf.displayMode.equalsIgnoreCase("binary")){ + int j = (int) Math.round(f.subtract(i,i1)); + String str = toBinaryString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("hexadecimal")){ + int j = (int) Math.round(f.subtract(i,i1)); + String str = toHexString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("octal")){ + int j = (int) Math.round(f.subtract(i,i1)); + String str = toOctalString(j); + Console.println("New Value is: " + str); + } + } else if (op.equals("*")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + if (sf.displayMode.equalsIgnoreCase("decimal")){ + Console.println("New Value is: " + f.multiply(i, i1)); + i = f.multiply(i, i1); + } + else if (sf.displayMode.equalsIgnoreCase("binary")){ + int j = (int) Math.round(f.multiply(i,i1)); + String str = toBinaryString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("hexadecimal")){ + int j = (int) Math.round(f.multiply(i,i1)); + String str = toHexString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("octal")){ + int j = (int) Math.round(f.multiply(i,i1)); + String str = toOctalString(j); + Console.println("New Value is: " + str); + } + } else if (op.equals("/")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + if (i1 == 0) { + Console.println("Err"); + } else { + if (sf.displayMode.equalsIgnoreCase("decimal")){ + Console.println("New Value is: " + f.divide(i, i1)); + i = f.divide(i,i1); } - t++; - } catch (Exception e) { - Console.println("Why are you the way that you are?"); - } - } while (t == 1); - } else if (op.equals("switch")) { - sf.switchDisplayMode(); - } else if (op.equals("M+")) { - sf.storeMemory(i); - } else if (op.equals("MC")) { - sf.clearMemory(); - } else if (op.equals("MRC")) { - Console.println("" + sf.memoryRecall()); - i = sf.memoryRecall(); - } else if (op.equals("Sine")) { - if (sf.unitsMode == "Degrees") { - Console.println("New Value is: " + sf.sine(i)); - i = sf.sine(i); - } else { - Console.println("New Value is: " + sf.sine(Math.toRadians(i))); - i = sf.sine(Math.toRadians(i)); - } - } else if (op.equals("Cosine")) { - if (sf.unitsMode == "Degrees") { - Console.println("New Value is: " + sf.cosine(i)); - i = sf.cosine(i); - } else { - Console.println("New Value is: " + sf.cosine(Math.toRadians(i))); - i = sf.cosine(Math.toRadians(i)); - } - } else if (op.equals("Tangent")) { - if (sf.unitsMode == "Degrees") { - Console.println("New Value is: " + sf.tangent(i)); - i = sf.tangent(i); - } else { - Console.println("New Value is: " + sf.tangent(Math.toRadians(i))); - i = sf.tangent(Math.toRadians(i)); - } - } else if (op.equals("invSine")) { - if (i < -1 || i > 1) { - Console.println("Err"); - } else { + else if (sf.displayMode.equalsIgnoreCase("binary")){ + int j = (int) Math.round(f.divide(i,i1)); + String str = toBinaryString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("hexadecimal")){ + int j = (int) Math.round(f.divide(i,i1)); + String str = toHexString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("octal")){ + int j = (int) Math.round(f.divide(i,i1)); + String str = toOctalString(j); + Console.println("New Value is: " + str); + } + } + } else if (op.equals("^y")) { + Double i1 = Console.getDoubleInput("Please enter next number:"); + if (sf.displayMode.equalsIgnoreCase("decimal")){ + Console.println("New Value is: " + f.exponent(i, i1)); + i = f.exponent(i,i1); + } + else if (sf.displayMode.equalsIgnoreCase("binary")){ + int j = (int) Math.round(f.exponent(i,i1)); + String str = toBinaryString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("hexadecimal")){ + int j = (int) Math.round(f.exponent(i,i1)); + String str = toHexString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("octal")){ + int j = (int) Math.round(f.exponent(i,i1)); + String str = toOctalString(j); + Console.println("New Value is: " + str); + } + } else if (op.equals("^2")) { + if (sf.displayMode.equalsIgnoreCase("decimal")){ + Console.println("New Value is: " + f.square(i)); + i = f.square(i); + } + else if (sf.displayMode.equalsIgnoreCase("binary")){ + int j = (int) Math.round(f.square(i)); + String str = toBinaryString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("hexadecimal")){ + int j = (int) Math.round(f.square(i)); + String str = toHexString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("octal")){ + int j = (int) Math.round(f.square(i)); + String str = toOctalString(j); + Console.println("New Value is: " + str); + } + } else if (op.equals("sqrt")) { + if (i < 0) { + Console.println("Err"); + } else { + if (sf.displayMode.equalsIgnoreCase("decimal")){ + Console.println("New Value is: " + f.root(i)); + i = f.root(i); + } + else if (sf.displayMode.equalsIgnoreCase("binary")){ + int j = (int) Math.round(f.root(i)); + String str = toBinaryString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("hexadecimal")){ + int j = (int) Math.round(f.root(i)); + String str = toHexString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("octal")){ + int j = (int) Math.round(f.root(i)); + String str = toOctalString(j); + Console.println("New Value is: " + str); + } + } + } else if (op.equals("inverse")) { + if (i == 0) { + Console.println("Err"); + } else { + if (sf.displayMode.equalsIgnoreCase("decimal")){ + Console.println("New Value is: " + f.inverse(i)); + i = f.inverse(i); + } + else if (sf.displayMode.equalsIgnoreCase("binary")){ + int j = (int) Math.round(f.inverse(i)); + String str = toBinaryString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("hexadecimal")){ + int j = (int) Math.round(f.inverse(i)); + String str = toHexString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("octal")){ + int j = (int) Math.round(f.inverse(i)); + String str = toOctalString(j); + Console.println("New Value is: " + str); + } + } + } else if (op.equals("invert")) { + if (sf.displayMode.equalsIgnoreCase("decimal")){ + Console.println("New Value is: " + f.invert(i)); + i = f.invert(i); + } + else if (sf.displayMode.equalsIgnoreCase("binary")){ + int j = (int) Math.round(f.invert(i)); + String str = toBinaryString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("hexadecimal")){ + int j = (int) Math.round(f.invert(i)); + String str = toHexString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("octal")){ + int j = (int) Math.round(f.invert(i)); + String str = toOctalString(j); + Console.println("New Value is: " + str); + } + } else if (op.equals("c")) { + Console.println("New Value is: " + f.clear()); + i = 0.0; + } else if (op.equals("end")) { + check = false; + r = 2; + } else if (op.equals("display()")) { + int t = 1; + do { + try { + String imp = Console.getOperationInput("Type binary, octal, decimal, hexadecimal"); + if (imp.equalsIgnoreCase("binary")) { + sf.switchDisplayMode("binary"); + } else if (imp.equalsIgnoreCase("octal")) { + sf.switchDisplayMode("octal"); + } else if (imp.equalsIgnoreCase("decimal")) { + sf.switchDisplayMode("decimal"); + } else if (imp.equalsIgnoreCase("hexadecimal")) { + sf.switchDisplayMode("hexadecimal"); + } + t++; + } catch (Exception e) { + Console.println("Why are you the way that you are?"); + } + } while (t == 1); + } else if (op.equals("display")) { + sf.switchDisplayMode(); + } else if (op.equals("M+")) { + sf.storeMemory(i); + } else if (op.equals("MC")) { + sf.clearMemory(); + } else if (op.equals("MRC")) { + Console.println("" + sf.memoryRecall()); + i = sf.memoryRecall(); + } else if (op.equals("Sine")) { if (sf.unitsMode == "Degrees") { - Console.println("New Value is: " + sf.sineInverse(i)); - i = sf.sineInverse(i); + Console.println("New Value is: " + sf.sine(i)); + i = sf.sine(i); } else { - Console.println("New Value is: " + sf.sineInverse(Math.toRadians(i))); - i = sf.sineInverse(Math.toRadians(i)); + Console.println("New Value is: " + sf.sine(Math.toRadians(i))); + i = sf.sine(Math.toRadians(i)); } - } - } else if (op.equals("invCosine")) { - if (i < -1 || i > 1) { - Console.println("Err"); - } else { + } else if (op.equals("Cosine")) { + if (sf.unitsMode == "Degrees") { + Console.println("New Value is: " + sf.cosine(i)); + i = sf.cosine(i); + } else { + Console.println("New Value is: " + sf.cosine(Math.toRadians(i))); + i = sf.cosine(Math.toRadians(i)); + } + } else if (op.equals("Tangent")) { if (sf.unitsMode == "Degrees") { - Console.println("New Value is: " + sf.cosineInverse(i)); - i = sf.cosineInverse(i); + Console.println("New Value is: " + sf.tangent(i)); + i = sf.tangent(i); } else { - Console.println("New Value is: " + sf.cosineInverse(Math.toRadians(i))); - i = sf.cosineInverse(Math.toRadians(i)); + Console.println("New Value is: " + sf.tangent(Math.toRadians(i))); + i = sf.tangent(Math.toRadians(i)); + } + } else if (op.equals("invSine")) { + if (i < -1 || i > 1) { + Console.println("Err"); + } else { + if (sf.unitsMode == "Degrees") { + Console.println("New Value is: " + sf.sineInverse(i)); + i = sf.sineInverse(i); + } else { + Console.println("New Value is: " + sf.sineInverse(Math.toRadians(i))); + i = sf.sineInverse(Math.toRadians(i)); + } } + } else if (op.equals("invCosine")) { + if (i < -1 || i > 1) { + Console.println("Err"); + } else { + if (sf.unitsMode == "Degrees") { + Console.println("New Value is: " + sf.cosineInverse(i)); + i = sf.cosineInverse(i); + } else { + Console.println("New Value is: " + sf.cosineInverse(Math.toRadians(i))); + i = sf.cosineInverse(Math.toRadians(i)); + } + } + } else if (op.equals("invTangent")) { + if (sf.unitsMode == "Degrees") { + Console.println("New Value is: " + sf.tangentInverse(i)); + i = sf.tangentInverse(i); + } else { + Console.println("New Value is: " + sf.tangentInverse(Math.toRadians(i))); + i = sf.tangentInverse(Math.toRadians(i)); + } + } else if (op.equals("units()")){ + int p = 1; + do { + try { + String useful = Console.getOperationInput("Enter degrees or radians"); + if (useful.equalsIgnoreCase("degrees")){ + sf.switchUnitsMode("Degrees"); + } + else if (useful.equalsIgnoreCase("radians")) { + sf.switchUnitsMode("Radians"); + } + p++; + } catch (Exception e){ + Console.println("Err"); + } + } while (p == 1); + } else if (op.equals("units")){ + sf.switchUnitsMode(); } - } else if (op.equals("invTangent")) { - if (sf.unitsMode == "Degrees") { - Console.println("New Value is: " + sf.tangentInverse(i)); - i = sf.tangentInverse(i); - } else { - Console.println("New Value is: " + sf.tangentInverse(Math.toRadians(i))); - i = sf.tangentInverse(Math.toRadians(i)); - } - } else if (op.equals("log")) { - if (i <= 0) { - Console.println("Err"); + else if (op.equals("log")) { + if (i <= 0) { + Console.println("Err"); + } else { + if (sf.displayMode.equalsIgnoreCase("decimal")){ + Console.println("New Value is: " + sf.logarithm(i)); + i = sf.logarithm(i); + } + else if (sf.displayMode.equalsIgnoreCase("binary")){ + int j = (int) Math.round(sf.logarithm(i)); + String str = toBinaryString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("hexadecimal")){ + int j = (int) Math.round(sf.logarithm(i)); + String str = toHexString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("octal")){ + int j = (int) Math.round(sf.logarithm(i)); + String str = toOctalString(j); + Console.println("New Value is: " + str); + } + } + } else if (op.equals("10^x")) { + if (sf.displayMode.equalsIgnoreCase("decimal")){ + Console.println("New Value is: " + sf.inverseLog(i)); + i = sf.inverseLog(i); + } + else if (sf.displayMode.equalsIgnoreCase("binary")){ + int j = (int) Math.round(sf.inverseLog(i)); + String str = toBinaryString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("hexadecimal")){ + int j = (int) Math.round(sf.inverseLog(i)); + String str = toHexString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("octal")){ + int j = (int) Math.round(sf.inverseLog(i)); + String str = toOctalString(j); + Console.println("New Value is: " + str); + } + } else if (op.equals("Ln")) { + if (i <= 0) { + Console.println("Err"); + } else { + if (sf.displayMode.equalsIgnoreCase("decimal")){ + Console.println("New Value is: " + sf.naturalLog(i)); + i = sf.naturalLog(i); + } + else if (sf.displayMode.equalsIgnoreCase("binary")){ + int j = (int) Math.round(sf.naturalLog(i)); + String str = toBinaryString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("hexadecimal")){ + int j = (int) Math.round(sf.naturalLog(i)); + String str = toHexString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("octal")){ + int j = (int) Math.round(sf.naturalLog(i)); + String str = toOctalString(j); + Console.println("New Value is: " + str); + } + } + } else if (op.equals("e^x")) { + if (sf.displayMode.equalsIgnoreCase("decimal")){ + Console.println("New Value is: " + sf.inverseNaturalLog(i)); + i = sf.inverseNaturalLog(i); + } + else if (sf.displayMode.equalsIgnoreCase("binary")){ + int j = (int) Math.round(sf.inverseNaturalLog(i)); + String str = toBinaryString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("hexadecimal")){ + int j = (int) Math.round(sf.inverseNaturalLog(i)); + String str = toHexString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("octal")){ + int j = (int) Math.round(sf.inverseNaturalLog(i)); + String str = toOctalString(j); + Console.println("New Value is: " + str); + } + } else if (op.equals("!")) { + int factor = Math.toIntExact(Math.round(i)); + Console.println("New Value is: " + sf.factorial(factor)); + i = Double.valueOf(sf.factorial(factor)); } else { - Console.println("New Value is: " + sf.logarithm(i)); - i = sf.logarithm(i); - } - } else if (op.equals("10^x")) { - Console.println("New Value is: " + sf.inverseLog(i)); - i = sf.inverseLog(i); - } else if (op.equals("Ln")) { - if (i <= 0) { Console.println("Err"); - } else { - Console.println("New Value is: " + sf.naturalLog(i)); - i = sf.naturalLog(i); } - } else if (op.equals("e^x")) { - Console.println("New Value is: " + sf.inverseNaturalLog(i)); - i = sf.inverseNaturalLog(i); - } else if (op.equals("!")) { - int factor = Math.toIntExact(Math.round(i)); - Console.println("New Value is: " + sf.factorial(factor)); - i = Double.valueOf(sf.factorial(factor)); - } else { - Console.println("Err"); - } - } catch (Exception e) { + } catch (Exception e) { - } - } while (r == 1); - } - } else if (calcDouble == 3) { - boolean check = true; - while (check) { - do { - try { - r = 1; - String op = Console.getOperationInput("Enter a shape you wish to work with: quad, circle, triangle or end(to exit)"); - if (op.equalsIgnoreCase("quad")){ - String info = Console.getOperationInput("Press r to return or continue to quadrilateral area with any key."); - if (info.equalsIgnoreCase("r")){ - } - else { + } + } while (r == 1); + } + } else if (calcDouble == 3) { + boolean check = true; + while (check) { + do { + try { + r = 1; + String op = Console.getOperationInput("Enter a shape you wish to work with: quad, circle, triangle or end(to exit)"); + if (op.equalsIgnoreCase("quad")) { + String info = Console.getOperationInput("Press r to return or continue to quadrilateral area with any key."); + if (info.equalsIgnoreCase("r")) { + } else { double w = Console.getDoubleInput("Enter the width"); double l = Console.getDoubleInput("Enter the length"); - if(w < 0 || l < 0){ + if (w < 0 || l < 0) { Console.println("Err"); - } - else{ - Console.println("The area of your quadrilateral is: " + shapes.quadArea(w,l)); + } else { + Console.println("The area of your quadrilateral is: " + shapes.quadArea(w, l)); } } - } - else if (op.equalsIgnoreCase("triangle")){ - String info1 = Console.getOperationInput("Press r to return or continue to triangle area with any key."); - if (info1.equalsIgnoreCase("r")){ - } - else { - double w = Console.getDoubleInput("Enter the width"); - double h = Console.getDoubleInput("Enter the height"); - if(w < 0 || h < 0){ - Console.println("Err"); - } - else{ - Console.println("The area of your triangle is: " + shapes.triangleArea(w, h)); - } - } - } - else if (op.equalsIgnoreCase("circle")){ - String info2 = Console.getOperationInput(("Press r to return or continue to circle area with any key.")); - if (info2.equalsIgnoreCase("r")){ - } - else { - double radius = Console.getDoubleInput("Enter the radius"); - if (radius < 0) { - Console.println("Err"); + } else if (op.equalsIgnoreCase("triangle")) { + String info1 = Console.getOperationInput("Press r to return or continue to triangle area with any key."); + if (info1.equalsIgnoreCase("r")) { + } else { + double w = Console.getDoubleInput("Enter the width"); + double h = Console.getDoubleInput("Enter the height"); + if (w < 0 || h < 0) { + Console.println("Err"); + } else { + Console.println("The area of your triangle is: " + shapes.triangleArea(w, h)); + } } - else { - Console.println("The area of your circle is "+ shapes.circleArea(radius)); + } else if (op.equalsIgnoreCase("circle")) { + String info2 = Console.getOperationInput(("Press r to return or continue to circle area with any key.")); + if (info2.equalsIgnoreCase("r")) { + } else { + double radius = Console.getDoubleInput("Enter the radius"); + if (radius < 0) { + Console.println("Err"); + } else { + Console.println("The area of your circle is " + shapes.circleArea(radius)); + } } - } - } - else if (op.equals("end")) { - check = false; - r = 2; - } + } else if (op.equalsIgnoreCase("end")) { + check = false; + r++; + } else { } + + } catch (Exception e) { + Console.println("Err"); } - catch (Exception e) { - Console.println("Err"); - } - } while (r == 1); + } while (r == 1); + } } + } catch (Exception e) { + Console.println("Err"); } - }catch (Exception e) { - Console.println("Err"); - } - } while (r == 1) ; + } while (r == 1); + } } } From 78216f4035a76101cb96c3a865b824294313d139 Mon Sep 17 00:00:00 2001 From: Chris Farmer Date: Sun, 9 Feb 2020 13:32:49 -0500 Subject: [PATCH 15/17] FINISHED --- .../scientificcalculator/MainApplication.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index b6528a28..f44cfbd5 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -503,8 +503,25 @@ else if (sf.displayMode.equalsIgnoreCase("octal")){ } } else if (op.equals("!")) { int factor = Math.toIntExact(Math.round(i)); - Console.println("New Value is: " + sf.factorial(factor)); - i = Double.valueOf(sf.factorial(factor)); + if (sf.displayMode.equalsIgnoreCase("decimal")){ + Console.println("New Value is: " + sf.factorial(factor)); + i = (double) sf.factorial(factor); + } + else if (sf.displayMode.equalsIgnoreCase("binary")){ + int j = (int) Math.round(sf.factorial(factor)); + String str = toBinaryString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("hexadecimal")){ + int j = (int) Math.round(sf.factorial(factor)); + String str = toHexString(j); + Console.println("New Value is: " + str); + } + else if (sf.displayMode.equalsIgnoreCase("octal")){ + int j = (int) Math.round(sf.factorial(factor)); + String str = toOctalString(j); + Console.println("New Value is: " + str); + } } else { Console.println("Err"); } From b67fc0fb6c98f2253bc53af07d19a3410efd357c Mon Sep 17 00:00:00 2001 From: Chris Farmer Date: Sun, 9 Feb 2020 13:54:26 -0500 Subject: [PATCH 16/17] tidied up some small errors --- .../scientificcalculator/MainApplication.java | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index f44cfbd5..3f971648 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -82,7 +82,7 @@ public static void main(String[] args) { i = 0.0; } else if (op.equals("end")) { check = false; - r = 2; + r++; } else { Console.println("Err"); } @@ -308,20 +308,26 @@ else if (sf.displayMode.equalsIgnoreCase("octal")){ i = 0.0; } else if (op.equals("end")) { check = false; - r = 2; + r++; } else if (op.equals("display()")) { int t = 1; do { try { String imp = Console.getOperationInput("Type binary, octal, decimal, hexadecimal"); if (imp.equalsIgnoreCase("binary")) { + Console.println("The display is now binary."); sf.switchDisplayMode("binary"); } else if (imp.equalsIgnoreCase("octal")) { + Console.println("The display is now octal."); sf.switchDisplayMode("octal"); } else if (imp.equalsIgnoreCase("decimal")) { + Console.println("The display is now decimal."); sf.switchDisplayMode("decimal"); } else if (imp.equalsIgnoreCase("hexadecimal")) { + Console.println("The display is now hexadecimal."); sf.switchDisplayMode("hexadecimal"); + } else { + Console.println("Invalid entry. \nWhy are you the way that you are?\nDo it right next time >:("); } t++; } catch (Exception e) { @@ -329,7 +335,22 @@ else if (sf.displayMode.equalsIgnoreCase("octal")){ } } while (t == 1); } else if (op.equals("display")) { - sf.switchDisplayMode(); + if (sf.displayMode.equalsIgnoreCase("binary")){ + Console.println("The display is now octal."); + sf.switchDisplayMode(); + } + else if (sf.displayMode.equalsIgnoreCase("octal")){ + Console.println("The display is now decimal."); + sf.switchDisplayMode(); + } + else if (sf.displayMode.equalsIgnoreCase("decimal")){ + Console.println("The display is now hexadecimal."); + sf.switchDisplayMode(); + } + else { + Console.println("The display is now binary."); + sf.switchDisplayMode(); + } } else if (op.equals("M+")) { sf.storeMemory(i); } else if (op.equals("MC")) { @@ -400,9 +421,11 @@ else if (sf.displayMode.equalsIgnoreCase("octal")){ try { String useful = Console.getOperationInput("Enter degrees or radians"); if (useful.equalsIgnoreCase("degrees")){ + Console.println("The mode is now Radians."); sf.switchUnitsMode("Degrees"); } else if (useful.equalsIgnoreCase("radians")) { + Console.println("The mode is now Degrees."); sf.switchUnitsMode("Radians"); } p++; @@ -411,7 +434,14 @@ else if (useful.equalsIgnoreCase("radians")) { } } while (p == 1); } else if (op.equals("units")){ - sf.switchUnitsMode(); + if (sf.unitsMode.equalsIgnoreCase("Degrees")){ + Console.println("The mode is now Radians."); + sf.switchUnitsMode();; + } + else { + Console.println("The mode is now Degrees."); + sf.switchUnitsMode(); + } } else if (op.equals("log")) { if (i <= 0) { From 863eeed78f40592c62da05b415836b700b39609e Mon Sep 17 00:00:00 2001 From: Chris Farmer Date: Mon, 10 Feb 2020 08:39:36 -0500 Subject: [PATCH 17/17] changed title --- .../scientificcalculator/MainApplication.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 3f971648..9d5c0a21 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -16,8 +16,8 @@ public static void main(String[] args) { sf.displayMode = "decimal"; sf.unitsMode = "Degrees"; - - Console.println("Welcome to my calculator!"); + Console.println("Designed by Chris, Maurice, and Ujjwal."); + Console.println("Welcome to the surprisely working calculator!"); String s = Console.getStringInput("Please enter your name?"); boolean eternal = true;