From 0d9e5978bda70130ca7b37704fff227dd2675f3d Mon Sep 17 00:00:00 2001 From: Maira Botelho Date: Sun, 20 Oct 2019 16:32:11 -0400 Subject: [PATCH 01/15] SimpleMath 1 --- .../scientificcalculator/SimpleMath.java | 43 ++++++++++++++++ .../scientific_calculator/TestSimpleMath.java | 50 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java create mode 100644 src/test/java/com/zipcodewilmington/scientific_calculator/TestSimpleMath.java diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java new file mode 100644 index 00000000..1ba0f712 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java @@ -0,0 +1,43 @@ +package com.zipcodewilmington.scientificcalculator; + +public class SimpleMath { + + /*Double num1; + Double num2; + + //Get first number from main class and set to the variables in this class + public void getNum1(double num1){ + this.num1 = num1; + } + public double setNum1() { + return this.num1; + } + + + public void getNum2(double num2){ + this.num2 = num2; + } + public double setNum2() { + return this.num2; + }*/ + + + //Simple Operations + public double add(double num1, double num2) { + return num1 + num2; + } + public Double subtract(double num1, double num2) { + return num1 - num2; + } + public Double multiplication(double num1, double num2){ + return num1 * num2; + } + public Double division(double num1, double num2){ + return num1 / num2; + } + + + + + +} \ No newline at end of file diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestSimpleMath.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestSimpleMath.java new file mode 100644 index 00000000..ce0cd6f4 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestSimpleMath.java @@ -0,0 +1,50 @@ +package com.zipcodewilmington.scientific_calculator; +import com.zipcodewilmington.scientificcalculator.SimpleMath; +import org.junit.Assert; + +public class TestSimpleMath { + + @org.junit.Before + public void setUp() throws Exception { + } + + @org.junit.After + public void tearDown() throws Exception{ + + } + + @org.junit.Test + public void testSimpleMath(){ + + SimpleMath add1 = new SimpleMath(); + Assert.assertEquals(20, add1.add(10,10), 0.00); + Assert.assertEquals(56.50, add1.add(20.25, 36.25), 0.00); + Assert.assertEquals(357, add1.add(206, 151), 0.00); + Assert.assertEquals(652.27, add1.add(563.25, 89.02), 0.00); + + + SimpleMath sub1 = new SimpleMath(); + Assert.assertEquals(15, sub1.subtract(20, 5), 0.00); + + + SimpleMath mul1 = new SimpleMath(); + Assert.assertEquals(81, mul1.multiplication(9,9), 0.00); + + + SimpleMath div1 = new SimpleMath(); + Assert.assertEquals(125, div1.division(250, 2), 0.00); + + + + + } + + + + + + +} + + + From bb5389678e5329d082fcd75f28c7caec3f2253d8 Mon Sep 17 00:00:00 2001 From: Ben Coon Date: Sun, 20 Oct 2019 16:32:33 -0400 Subject: [PATCH 02/15] Maybe working interface...? --- .../scientificcalculator/Console.java | 10 +-- .../scientificcalculator/MainApplication.java | 77 +++++++++++++++++-- 2 files changed, 76 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index 83f0e97f..e14ba007 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -22,11 +22,11 @@ public static String getStringInput(String prompt) { return userInput; } - public static Integer getIntegerInput(String prompt) { - return null; - } - public static Double getDoubleInput(String prompt) { - return null; + Scanner scanner = new Scanner(System.in); + println(prompt); + Double userInput = Double.valueOf(scanner.nextLine()); + return userInput; } + } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 5f421325..82090006 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -4,14 +4,79 @@ * Created by leon on 2/9/18. */ public class MainApplication { + + + public static void main(String[] args) { + + double result = 1.0; + 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."); + String operation = Console.getStringInput("Enter the operation you would like to perform."); + Double num1 = Console.getDoubleInput("Enter your first number."); + + switch(operation) { + case "+": + Double num2 = Console.getDoubleInput("Enter your second."); + return System.out.println(num1 + " / " + num2 + " = " + result); + break; + case "-": + Double num2 = Console.getDoubleInput("Enter your second number."); + return System.out.println(num1 + " - " + num2 + " = " + result); + break; + case "x": + Double num2 = Console.getDoubleInput("Enter your second number."); + return System.out.println(num1 + " x " + num2 + " = " + result); + break; + case "/": + Double num2 = Console.getDoubleInput("Enter your second number."); + return System.out.println(num1 + " / " + num2 + " = " + result); + break; + case "sq": + return System.out.println(num1 + " squared is " + result); + break; + case "exp": + return System.out.println(num1 + " to the power of " + num2 + " = " + result); + break; + case "sqrt": + return System.out.println("The square root of " + num1 + " is " + result); + break; + case "inverse": + return System.out.println("The inverse of " + num1 + " is " + result); + break; + case "log": + return System.out.println("The inverse of " + num1 + " is " + result); + break; + case "sine": + return System.out.println("The sine of " + num1 + " is " + result); + break; + case "cosine": + return System.out.println("The cosine of " + num1 + " is " + result); + break; + case "tangent": + return System.out.println("The tangent of " + num1 + " is " + result); + break; + default: + return System.out.println("Your input was incorrect please type one of the following:\n" + + "+ for addition \n- for subtraction\nx for multiplication\n/ for division\n" + + "sq for squaring \nexp for exponent\nsqrt for squart root\ninv for inverse\n" + + "inv for invert\nlog for logarithms\nsin for sine\ncos for cosine\ntan for tangent\n"); + break; + + + + } + + + //Double num1 = Console.getDoubleInput("Enter your first number."); + //Double num2 = Console.getDoubleInput("Enter a double."); + + Console.println("The user input %s as a string", operation); + Console.println("The user input %s as a integer", num1); + Console.println("The user input %s as a d", num2); + + - 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); } + } From 27af6a452299e569207b7a2a2ff57a6f78fd86fa Mon Sep 17 00:00:00 2001 From: Ben Coon Date: Sun, 20 Oct 2019 17:27:39 -0400 Subject: [PATCH 03/15] Interface working with finished portions of Simple Calculator --- pom.xml | 14 ++++ .../scientificcalculator/Console.java | 4 +- .../scientificcalculator/MainApplication.java | 81 ++++++++++--------- .../scientificcalculator/SimpleMath.java | 6 +- .../scientific_calculator/TestSimpleMath.java | 1 + 5 files changed, 63 insertions(+), 43 deletions(-) diff --git a/pom.xml b/pom.xml index e7cb4f6b..2a2315d1 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,20 @@ com.zipcodewilmington scientific_calculator 1.0-SNAPSHOT + + + org.junit.jupiter + junit-jupiter-api + RELEASE + test + + + junit + junit + 4.12 + test + + \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index e14ba007..1eb4c71c 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -15,10 +15,10 @@ public static void println(String output, Object... args) { print(output + "\n", args); } - public static String getStringInput(String prompt) { + public static Integer getIntegerInput(String prompt) { Scanner scanner = new Scanner(System.in); println(prompt); - String userInput = scanner.nextLine(); + Integer userInput = Integer.valueOf(scanner.nextLine()); return userInput; } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 82090006..0732feb8 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -8,59 +8,70 @@ public class MainApplication { public static void main(String[] args) { + SimpleMath simpleMath = new SimpleMath(); double result = 1.0; - Console.println("Welcome to my calculator!"); - String operation = Console.getStringInput("Enter the operation you would like to perform."); + Console.println("Welcome to my calculator!\n" + + "1 for addition \n2 for subtraction\n3 for multiplication\n4 for division\n" + + "5 for squaring \n6 for exponent\n7 for square root\n8 for inverse\n" + + "9 for invert\n10 for logarithms\n11 for sine\n12 for cosine\n13 tan for tangent\n"); + + Integer operation = Console.getIntegerInput("Enter the operation you would like to perform."); Double num1 = Console.getDoubleInput("Enter your first number."); switch(operation) { - case "+": + case 1: Double num2 = Console.getDoubleInput("Enter your second."); - return System.out.println(num1 + " / " + num2 + " = " + result); + result = simpleMath.add(num1, num2); + System.out.println(num1 + " + " + num2 + " = " + result); break; - case "-": - Double num2 = Console.getDoubleInput("Enter your second number."); - return System.out.println(num1 + " - " + num2 + " = " + result); + case 2: + num2 = Console.getDoubleInput("Enter your second number."); + result = simpleMath.subtract(num1, num2); + System.out.println(num1 + " - " + num2 + " = " + result); break; - case "x": - Double num2 = Console.getDoubleInput("Enter your second number."); - return System.out.println(num1 + " x " + num2 + " = " + result); + case 3: + num2 = Console.getDoubleInput("Enter your second number."); + result = simpleMath.multiplication(num1, num2); + System.out.println(num1 + " x " + num2 + " = " + result); break; - case "/": - Double num2 = Console.getDoubleInput("Enter your second number."); - return System.out.println(num1 + " / " + num2 + " = " + result); + case 4: + num2 = Console.getDoubleInput("Enter your second number."); + result = simpleMath.division(num1, num2); + System.out.println(num1 + " / " + num2 + " = " + result); break; - case "sq": - return System.out.println(num1 + " squared is " + result); + case 5: + System.out.println(num1 + " squared is " + result); break; - case "exp": - return System.out.println(num1 + " to the power of " + num2 + " = " + result); + case 6: + num2 = Console.getDoubleInput("Enter your second number."); + //simpleMath.exponent(num1, num2); + System.out.println(num1 + " to the power of " + num2 + " = " + result); break; - case "sqrt": - return System.out.println("The square root of " + num1 + " is " + result); + case 7: + System.out.println("The square root of " + num1 + " is " + result); break; - case "inverse": - return System.out.println("The inverse of " + num1 + " is " + result); + case 8: + System.out.println("The inverse of " + num1 + " is " + result); break; - case "log": - return System.out.println("The inverse of " + num1 + " is " + result); + case 9: + System.out.println("The logarithm of " + num1 + " is " + result); break; - case "sine": - return System.out.println("The sine of " + num1 + " is " + result); + case 10: + System.out.println("The sine of " + num1 + " is " + result); break; - case "cosine": - return System.out.println("The cosine of " + num1 + " is " + result); + case 11: + System.out.println("The cosine of " + num1 + " is " + result); break; - case "tangent": - return System.out.println("The tangent of " + num1 + " is " + result); + case 12: + System.out.println("The tangent of " + num1 + " is " + result); break; default: - return System.out.println("Your input was incorrect please type one of the following:\n" + - "+ for addition \n- for subtraction\nx for multiplication\n/ for division\n" + - "sq for squaring \nexp for exponent\nsqrt for squart root\ninv for inverse\n" + - "inv for invert\nlog for logarithms\nsin for sine\ncos for cosine\ntan for tangent\n"); + System.out.println("Your input was incorrect please type one of the following:\n" + + "1 for addition \n2 for subtraction\n3 for multiplication\n4 for division\n" + + "5 for squaring \n6 for exponent\n7 for square root\n8 for inverse\n" + + "9 for invert\n10 for logarithms\n11 for sine\n12 for cosine\ntan for tangent\n"); break; @@ -71,9 +82,7 @@ public static void main(String[] args) { //Double num1 = Console.getDoubleInput("Enter your first number."); //Double num2 = Console.getDoubleInput("Enter a double."); - Console.println("The user input %s as a string", operation); - Console.println("The user input %s as a integer", num1); - Console.println("The user input %s as a d", num2); + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java index 1ba0f712..f96635a3 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java @@ -23,7 +23,7 @@ public double setNum2() { //Simple Operations - public double add(double num1, double num2) { + public Double add(double num1, double num2) { return num1 + num2; } public Double subtract(double num1, double num2) { @@ -36,8 +36,4 @@ public Double division(double num1, double num2){ return num1 / num2; } - - - - } \ No newline at end of file diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestSimpleMath.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestSimpleMath.java index ce0cd6f4..7574d00b 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestSimpleMath.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestSimpleMath.java @@ -2,6 +2,7 @@ import com.zipcodewilmington.scientificcalculator.SimpleMath; import org.junit.Assert; + public class TestSimpleMath { @org.junit.Before From 3c256741674dd4d33f23652b56cf5f77b151dd97 Mon Sep 17 00:00:00 2001 From: Maira Botelho Date: Sun, 20 Oct 2019 18:03:24 -0400 Subject: [PATCH 04/15] SimpleMath 2 --- .../scientificcalculator/Console.java | 10 ++- .../scientificcalculator/SimpleMath.java | 24 ++++++- .../scientific_calculator/TestSimpleMath.java | 72 ++++++++++++++++++- 3 files changed, 101 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index 83f0e97f..fe4d1c84 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -23,10 +23,16 @@ public static String getStringInput(String prompt) { } public static Integer getIntegerInput(String prompt) { - return null; + Scanner scanner = new Scanner(System.in); + println(prompt); + Integer userInput = Integer.valueOf(scanner.nextLine()); + return userInput; } public static Double getDoubleInput(String prompt) { - return null; + Scanner scanner = new Scanner(System.in); + println(prompt); + Double userInput = Double.valueOf(scanner.nextLine()); + return userInput; } } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java index 1ba0f712..09b8dd4e 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java @@ -1,5 +1,7 @@ package com.zipcodewilmington.scientificcalculator; +import static java.lang.Math.sqrt; + public class SimpleMath { /*Double num1; @@ -23,7 +25,7 @@ public double setNum2() { //Simple Operations - public double add(double num1, double num2) { + public Double add(double num1, double num2) { return num1 + num2; } public Double subtract(double num1, double num2) { @@ -36,6 +38,26 @@ public Double division(double num1, double num2){ return num1 / num2; } + public Double square(double num1){ + return num1 * num1; + } + + public Double squareRoot(double num1){ + return Math.sqrt(num1); + } + + public Double expo(double num1, double num2){ + return Math.pow(num1, num2); + } + + public Double inverse(double num1){ + return 1 / num1; + } + + public Double invertSign(double num1){ + return num1 * -1; + } + diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestSimpleMath.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestSimpleMath.java index ce0cd6f4..a760ffc2 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestSimpleMath.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestSimpleMath.java @@ -14,33 +14,100 @@ public void tearDown() throws Exception{ } @org.junit.Test - public void testSimpleMath(){ + public void testSimpleMathAdd() { SimpleMath add1 = new SimpleMath(); - Assert.assertEquals(20, add1.add(10,10), 0.00); + Assert.assertEquals(20, add1.add(10, 10), 0.00); Assert.assertEquals(56.50, add1.add(20.25, 36.25), 0.00); Assert.assertEquals(357, add1.add(206, 151), 0.00); Assert.assertEquals(652.27, add1.add(563.25, 89.02), 0.00); + } + @org.junit.Test + public void testSimpleMathSub(){ SimpleMath sub1 = new SimpleMath(); Assert.assertEquals(15, sub1.subtract(20, 5), 0.00); + Assert.assertEquals(378, sub1.subtract(456, 78), 0.00); + Assert.assertEquals(55.64, sub1.subtract(89.67, 34.03), 0.00); + Assert.assertEquals(28, sub1.subtract(37,9), 0.00); + } + + @org.junit.Test + public void testSimpleMathMul(){ SimpleMath mul1 = new SimpleMath(); Assert.assertEquals(81, mul1.multiplication(9,9), 0.00); + Assert.assertEquals(150.4, mul1.multiplication(37.6,4), 0.00); + Assert.assertEquals(120, mul1.multiplication(30,4), 0.00); + Assert.assertEquals(950, mul1.multiplication(100,9.5), 0.00); + } + + @org.junit.Test + public void testSimpleMathDiv(){ SimpleMath div1 = new SimpleMath(); Assert.assertEquals(125, div1.division(250, 2), 0.00); + Assert.assertEquals(14.383333333333333, div1.division(86.3, 6), 0.00); + Assert.assertEquals(18.666666666666668, div1.division(56, 3), 0.00); + Assert.assertEquals(3, div1.division(21, 7), 0.00); + + } + + + @org.junit.Test + public void testSimpleMathSq() { + SimpleMath square1 = new SimpleMath(); + Assert.assertEquals(4, square1.square(2), 0.00); + Assert.assertEquals(625, square1.square(25), 0.00); + Assert.assertEquals(529, square1.square(23), 0.00); + Assert.assertEquals(90.25, square1.square(9.5), 0.00); + } + @org.junit.Test + public void testSimpleMathSqRt() { + SimpleMath sqRoot1 = new SimpleMath(); + Assert.assertEquals(7, sqRoot1.squareRoot(49), 0.00); + Assert.assertEquals(4.878524367060187, sqRoot1.squareRoot(23.8), 0.00); + Assert.assertEquals(10.099504938362077, sqRoot1.squareRoot(102), 0.00); + Assert.assertEquals(1.449137674618944, sqRoot1.squareRoot(2.1), 0.00); } + @org.junit.Test + public void testSimpleMathExpo() { + SimpleMath expo1 = new SimpleMath(); + Assert.assertEquals(1000, expo1.expo(10, 3), 0.00); + Assert.assertEquals(97.65625, expo1.expo(2.5, 5), 0.00); + Assert.assertEquals(64, expo1.expo(2, 6), 0.00); + Assert.assertEquals(300.76300000000003, expo1.expo(6.7, 3), 0.00); + } + @org.junit.Test + public void testSimpleMathInverse() { + + SimpleMath inverse1 = new SimpleMath(); + Assert.assertEquals(0.125, inverse1.inverse(8), 0.00); + Assert.assertEquals(0.16129032258064516, inverse1.inverse(6.2), 0.00); + Assert.assertEquals(0.043478260869565216, inverse1.inverse(23), 0.00); + Assert.assertEquals(0.998003992015968, inverse1.inverse(1.002), 0.00); + } + + @org.junit.Test + public void testSimpleMathInvertSign() { + + SimpleMath sign1 = new SimpleMath(); + Assert.assertEquals(- 9, sign1.invertSign(9), 0.00); + Assert.assertEquals(56, sign1.invertSign(- 56), 0.00); + Assert.assertEquals(- 123.34, sign1.invertSign(123.34), 0.00); + Assert.assertEquals(34.02, sign1.invertSign(- 34.02), 0.00); + + } @@ -48,3 +115,4 @@ public void testSimpleMath(){ + From a8c4012b93fca0de9c7d2797b6e8edf6aea6afa8 Mon Sep 17 00:00:00 2001 From: Ben Coon Date: Sun, 20 Oct 2019 18:28:54 -0400 Subject: [PATCH 05/15] Working Simple Calc --- .../scientificcalculator/MainApplication.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 0732feb8..f3312134 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -42,36 +42,52 @@ public static void main(String[] args) { System.out.println(num1 + " / " + num2 + " = " + result); break; case 5: + simpleMath.square(num1); System.out.println(num1 + " squared is " + result); break; case 6: num2 = Console.getDoubleInput("Enter your second number."); - //simpleMath.exponent(num1, num2); + simpleMath.expo(num1, num2); System.out.println(num1 + " to the power of " + num2 + " = " + result); break; case 7: + simpleMath.squareRoot(num1); System.out.println("The square root of " + num1 + " is " + result); break; case 8: + simpleMath.inverse(num1); System.out.println("The inverse of " + num1 + " is " + result); break; case 9: + simpleMath.invertSign(num1); + System.out.println("The invert of " + num1 + " is " + result); + case 10: System.out.println("The logarithm of " + num1 + " is " + result); break; - case 10: + case 11: System.out.println("The sine of " + num1 + " is " + result); break; - case 11: + case 12: System.out.println("The cosine of " + num1 + " is " + result); break; - case 12: + case 13: System.out.println("The tangent of " + num1 + " is " + result); break; + case 14: + System.out.println("The arcsine of " + num1 + " is " + result); + break; + case 15: + System.out.println("The arccosine of " + num1 + " is " + result); + break; + case 16: + System.out.println("The arctangent of " + num1 + " is " + result); + break; default: System.out.println("Your input was incorrect please type one of the following:\n" + "1 for addition \n2 for subtraction\n3 for multiplication\n4 for division\n" + "5 for squaring \n6 for exponent\n7 for square root\n8 for inverse\n" + - "9 for invert\n10 for logarithms\n11 for sine\n12 for cosine\ntan for tangent\n"); + "9 for invert\n10 for logarithms\n11 for sine\n12 for cosine\n13 tan for tangent\n" + + "14 for arcsine\n15 for arccosine\n16 for arctangent"); break; From c9288b71fcf6c173d4ae4326510c39b8fedf5ac4 Mon Sep 17 00:00:00 2001 From: Ben Coon Date: Sun, 20 Oct 2019 18:31:42 -0400 Subject: [PATCH 06/15] Actual Working Simple Calc --- .../scientificcalculator/MainApplication.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index f3312134..494b2783 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -42,24 +42,24 @@ public static void main(String[] args) { System.out.println(num1 + " / " + num2 + " = " + result); break; case 5: - simpleMath.square(num1); + result = simpleMath.square(num1); System.out.println(num1 + " squared is " + result); break; case 6: num2 = Console.getDoubleInput("Enter your second number."); - simpleMath.expo(num1, num2); + result = simpleMath.expo(num1, num2); System.out.println(num1 + " to the power of " + num2 + " = " + result); break; case 7: - simpleMath.squareRoot(num1); + result = simpleMath.squareRoot(num1); System.out.println("The square root of " + num1 + " is " + result); break; case 8: - simpleMath.inverse(num1); + result = simpleMath.inverse(num1); System.out.println("The inverse of " + num1 + " is " + result); break; case 9: - simpleMath.invertSign(num1); + result = simpleMath.invertSign(num1); System.out.println("The invert of " + num1 + " is " + result); case 10: System.out.println("The logarithm of " + num1 + " is " + result); From 141c43c3583843553f21c5d113d93955b5e49029 Mon Sep 17 00:00:00 2001 From: Maira Botelho Date: Sun, 20 Oct 2019 18:57:53 -0400 Subject: [PATCH 07/15] SwitchDisplay 1 --- .../scientificcalculator/SwitchDisplay.java | 16 ++++++ .../TestSwitchDisplay.java | 52 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java create mode 100644 src/test/java/com/zipcodewilmington/scientific_calculator/TestSwitchDisplay.java diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java new file mode 100644 index 00000000..11315315 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java @@ -0,0 +1,16 @@ +package com.zipcodewilmington.scientificcalculator; + +public class SwitchDisplay { + + public String toBinary(int num1){ + return Integer.toBinaryString(num1); + } + + public String toOctal(int num1){ + return Integer.toOctalString(num1); + } + + public String toHex(int num1){ + return Integer.toHexString(num1); + } +} diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestSwitchDisplay.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestSwitchDisplay.java new file mode 100644 index 00000000..175fb798 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestSwitchDisplay.java @@ -0,0 +1,52 @@ +package com.zipcodewilmington.scientific_calculator; + + +import com.zipcodewilmington.scientificcalculator.SwitchDisplay; +import org.junit.Assert; + +public class TestSwitchDisplay { + + @org.junit.Before + public void setUp() throws Exception { + } + + @org.junit.After + public void tearDown() throws Exception{ + + } + + + @org.junit.Test + public void testSwitchDisplayBinary(){ + + SwitchDisplay binary1 = new SwitchDisplay(); + Assert.assertEquals("10111", binary1.toBinary(23)); + Assert.assertEquals("1000110111", binary1.toBinary(567)); + Assert.assertEquals("10001100101000", binary1.toBinary(9000)); + Assert.assertEquals("1001001", binary1.toBinary(73)); + + } + + @org.junit.Test + public void testSwitchDisplayOctal(){ + + SwitchDisplay octal1 = new SwitchDisplay(); + Assert.assertEquals("27", octal1.toOctal(23)); + Assert.assertEquals("173", octal1.toOctal(123)); + Assert.assertEquals("1067", octal1.toOctal(567)); + Assert.assertEquals("21460", octal1.toOctal(9008)); + + + } + + @org.junit.Test + public void testSwitchDisplayHex(){ + + SwitchDisplay hex1 = new SwitchDisplay(); + Assert.assertEquals("17", hex1.toHex(23)); + Assert.assertEquals("1cb", hex1.toHex(459)); + Assert.assertEquals("30c", hex1.toHex(780)); + Assert.assertEquals("2d", hex1.toHex(45)); + } + +} From 06ad934124e33383e7f1df6d8ffba3e121103fa3 Mon Sep 17 00:00:00 2001 From: Maira Botelho Date: Sun, 20 Oct 2019 19:00:11 -0400 Subject: [PATCH 08/15] SwitchDisplay 1 --- .../zipcodewilmington/scientificcalculator/SwitchDisplay.java | 1 + .../scientific_calculator/TestSwitchDisplay.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java index 11315315..f8d00867 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java @@ -14,3 +14,4 @@ public String toHex(int num1){ return Integer.toHexString(num1); } } + diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestSwitchDisplay.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestSwitchDisplay.java index 175fb798..30f67f6d 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestSwitchDisplay.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestSwitchDisplay.java @@ -50,3 +50,4 @@ public void testSwitchDisplayHex(){ } } + From 135fbde4cc9d7ef8153c404a88c5a2878fc47ea1 Mon Sep 17 00:00:00 2001 From: Maira Botelho Date: Sun, 20 Oct 2019 19:03:12 -0400 Subject: [PATCH 09/15] new changes --- pom.xml | 8 ++++++++ .../scientificcalculator/MainApplication.java | 9 +++++++-- .../scientificcalculator/SimpleMath.java | 20 ------------------- .../scientificcalculator/SwitchDisplay.java | 1 + .../TestSwitchDisplay.java | 1 + 5 files changed, 17 insertions(+), 22 deletions(-) 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/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 5f421325..f004b4d9 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -8,10 +8,15 @@ public static void main(String[] args) { 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."); + Integer ii = 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); + Console.println("The user input %s as a integer", ii); + //Console.println("The user input %s as a d", d); + } + } + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java index 09b8dd4e..5a2d86df 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java @@ -4,26 +4,6 @@ public class SimpleMath { - /*Double num1; - Double num2; - - //Get first number from main class and set to the variables in this class - public void getNum1(double num1){ - this.num1 = num1; - } - public double setNum1() { - return this.num1; - } - - - public void getNum2(double num2){ - this.num2 = num2; - } - public double setNum2() { - return this.num2; - }*/ - - //Simple Operations public Double add(double num1, double num2) { return num1 + num2; diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java index f8d00867..b6c0c22b 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java @@ -15,3 +15,4 @@ public String toHex(int num1){ } } + diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestSwitchDisplay.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestSwitchDisplay.java index 30f67f6d..59b723f9 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestSwitchDisplay.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestSwitchDisplay.java @@ -51,3 +51,4 @@ public void testSwitchDisplayHex(){ } + From 28c6a0195cff51949b5909c76f25e54b98919d81 Mon Sep 17 00:00:00 2001 From: Ben Coon Date: Sun, 20 Oct 2019 21:15:53 -0400 Subject: [PATCH 10/15] Code so far --- .../scientificcalculator/MainApplication.java | 37 ++++++++++--------- .../scientificcalculator/Settings.java | 6 +++ .../scientificcalculator/SimpleMath.java | 23 ------------ 3 files changed, 26 insertions(+), 40 deletions(-) create mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/Settings.java diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 494b2783..9f9527c3 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -5,8 +5,6 @@ */ public class MainApplication { - - public static void main(String[] args) { SimpleMath simpleMath = new SimpleMath(); @@ -21,6 +19,9 @@ public static void main(String[] args) { Double num1 = Console.getDoubleInput("Enter your first number."); switch(operation) { + case 0: + + case 1: Double num2 = Console.getDoubleInput("Enter your second."); result = simpleMath.add(num1, num2); @@ -38,8 +39,12 @@ public static void main(String[] args) { break; case 4: num2 = Console.getDoubleInput("Enter your second number."); - result = simpleMath.division(num1, num2); - System.out.println(num1 + " / " + num2 + " = " + result); + if (num2 != 0) { + result = simpleMath.division(num1, num2); + System.out.println(num1 + " / " + num2 + " = " + result); + } else { + System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); + } break; case 5: result = simpleMath.square(num1); @@ -56,11 +61,20 @@ public static void main(String[] args) { break; case 8: result = simpleMath.inverse(num1); - System.out.println("The inverse of " + num1 + " is " + result); + if (num1 != 0) { + System.out.println("The inverse of " + num1 + " is " + result); + } else { + System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); + } break; case 9: result = simpleMath.invertSign(num1); - System.out.println("The invert of " + num1 + " is " + result); + if (num1 != 0) { + System.out.println("The invert of " + num1 + " is " + result); + } else { + System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); + } + break; case 10: System.out.println("The logarithm of " + num1 + " is " + result); break; @@ -89,19 +103,8 @@ public static void main(String[] args) { "9 for invert\n10 for logarithms\n11 for sine\n12 for cosine\n13 tan for tangent\n" + "14 for arcsine\n15 for arccosine\n16 for arctangent"); break; - - - } - - //Double num1 = Console.getDoubleInput("Enter your first number."); - //Double num2 = Console.getDoubleInput("Enter a double."); - - - - - } } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Settings.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Settings.java new file mode 100644 index 00000000..1db04914 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Settings.java @@ -0,0 +1,6 @@ +package com.zipcodewilmington.scientificcalculator; + +public class Settings { + + +} diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java index f98a426b..fd46226e 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java @@ -4,25 +4,6 @@ public class SimpleMath { - /*Double num1; - Double num2; - - //Get first number from main class and set to the variables in this class - public void getNum1(double num1){ - this.num1 = num1; - } - public double setNum1() { - return this.num1; - } - - - public void getNum2(double num2){ - this.num2 = num2; - } - public double setNum2() { - return this.num2; - }*/ - //Simple Operations public Double add(double num1, double num2) { @@ -57,8 +38,4 @@ public Double inverse(double num1){ public Double invertSign(double num1){ return num1 * -1; } - - - - } \ No newline at end of file From 2dfef4adfbc4c34ad5cb609c4dab417993c49f6d Mon Sep 17 00:00:00 2001 From: Ben Coon Date: Sun, 20 Oct 2019 22:02:53 -0400 Subject: [PATCH 11/15] As good as it gets for now lol --- pom.xml | 12 ++ .../scientificcalculator/LogFunctions.java | 20 ++ .../scientificcalculator/MainApplication.java | 185 +++++++++--------- .../ScientificFunctions.java | 38 ++++ .../LogFunctionsTest.java | 44 +++++ .../TestScientificFunctions.java | 67 +++++++ 6 files changed, 274 insertions(+), 92 deletions(-) create mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/LogFunctions.java create mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java create mode 100644 src/test/java/com/zipcodewilmington/scientific_calculator/LogFunctionsTest.java create mode 100644 src/test/java/com/zipcodewilmington/scientific_calculator/TestScientificFunctions.java diff --git a/pom.xml b/pom.xml index e0139827..d3824273 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,18 @@ 4.12 test + + junit + junit + 4.12 + compile + + + junit + junit + 4.12 + compile + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/LogFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/LogFunctions.java new file mode 100644 index 00000000..028072f2 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/LogFunctions.java @@ -0,0 +1,20 @@ +package com.zipcodewilmington.scientificcalculator; + +public class LogFunctions { + public Double log(double num1) { + return Math.log10(num1); + } + + public Double inverseLog(double num1) { + return Math.pow(10, num1); + } + + public Double naturalLog(double num1) { + return Math.log(num1); + } + + public Double inverseNatutalLog(double num1) { + return Math.pow(2.71828182846, num1); + } +} + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 67ad372f..7b1e27f1 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -7,104 +7,105 @@ public class MainApplication { public static void main(String[] args) { - SimpleMath simpleMath = new SimpleMath(); + SimpleMath simpleMath = new SimpleMath(); - double result = 1.0; + double result = 1.0; - Console.println("Welcome to my calculator!\n" + - "1 for addition \n2 for subtraction\n3 for multiplication\n4 for division\n" + - "5 for squaring \n6 for exponent\n7 for square root\n8 for inverse\n" + - "9 for invert\n10 for logarithms\n11 for sine\n12 for cosine\n13 tan for tangent\n"); + Console.println("Welcome to my calculator!\n" + + "1 for addition \n2 for subtraction\n3 for multiplication\n4 for division\n" + + "5 for squaring \n6 for exponent\n7 for square root\n8 for inverse\n" + + "9 for invert\n10 for logarithms\n11 for sine\n12 for cosine\n13 tan for tangent\n"); - Integer operation = Console.getIntegerInput("Enter the operation you would like to perform."); - Double num1 = Console.getDoubleInput("Enter your first number."); + Integer operation = Console.getIntegerInput("Enter the operation you would like to perform."); + Double num1 = Console.getDoubleInput("Enter your first number."); + + switch (operation) { + case 1: + Double num2 = Console.getDoubleInput("Enter your second."); + result = simpleMath.add(num1, num2); + System.out.println(num1 + " + " + num2 + " = " + result); + break; + case 2: + num2 = Console.getDoubleInput("Enter your second number."); + result = simpleMath.subtract(num1, num2); + System.out.println(num1 + " - " + num2 + " = " + result); + break; + case 3: + num2 = Console.getDoubleInput("Enter your second number."); + result = simpleMath.multiplication(num1, num2); + System.out.println(num1 + " x " + num2 + " = " + result); + break; + case 4: + num2 = Console.getDoubleInput("Enter your second number."); + if (num2 != 0) { + result = simpleMath.division(num1, num2); + System.out.println(num1 + " / " + num2 + " = " + result); + } else { + System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); + } + break; + case 5: + result = simpleMath.square(num1); + System.out.println(num1 + " squared is " + result); + break; + case 6: + num2 = Console.getDoubleInput("Enter your second number."); + result = simpleMath.expo(num1, num2); + System.out.println(num1 + " to the power of " + num2 + " = " + result); + break; + case 7: + result = simpleMath.squareRoot(num1); + System.out.println("The square root of " + num1 + " is " + result); + break; + case 8: + result = simpleMath.inverse(num1); + if (num1 != 0) { + System.out.println("The inverse of " + num1 + " is " + result); + } else { + System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); + } + break; + case 9: + result = simpleMath.invertSign(num1); + if (num1 != 0) { + System.out.println("The invert of " + num1 + " is " + result); + } else { + System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); + } + break; + case 10: + System.out.println("The logarithm of " + num1 + " is " + result); + break; + case 11: + System.out.println("The sine of " + num1 + " is " + result); + break; + case 12: + System.out.println("The cosine of " + num1 + " is " + result); + break; + case 13: + System.out.println("The tangent of " + num1 + " is " + result); + break; + case 14: + System.out.println("The arcsine of " + num1 + " is " + result); + break; + case 15: + System.out.println("The arccosine of " + num1 + " is " + result); + break; + case 16: + System.out.println("The arctangent of " + num1 + " is " + result); + break; + default: + System.out.println("Your input was incorrect please type one of the following:\n" + + "1 for addition \n2 for subtraction\n3 for multiplication\n4 for division\n" + + "5 for squaring \n6 for exponent\n7 for square root\n8 for inverse\n" + + "9 for invert\n10 for logarithms\n11 for sine\n12 for cosine\n13 tan for tangent\n" + + "14 for arcsine\n15 for arccosine\n16 for arctangent"); + break; + } - switch(operation) { - case 1: - Double num2 = Console.getDoubleInput("Enter your second."); - result = simpleMath.add(num1, num2); - System.out.println(num1 + " + " + num2 + " = " + result); - break; - case 2: - num2 = Console.getDoubleInput("Enter your second number."); - result = simpleMath.subtract(num1, num2); - System.out.println(num1 + " - " + num2 + " = " + result); - break; - case 3: - num2 = Console.getDoubleInput("Enter your second number."); - result = simpleMath.multiplication(num1, num2); - System.out.println(num1 + " x " + num2 + " = " + result); - break; - case 4: - num2 = Console.getDoubleInput("Enter your second number."); - if (num2 != 0) { - result = simpleMath.division(num1, num2); - System.out.println(num1 + " / " + num2 + " = " + result); - } else { - System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); - } - break; - case 5: - result = simpleMath.square(num1); - System.out.println(num1 + " squared is " + result); - break; - case 6: - num2 = Console.getDoubleInput("Enter your second number."); - result = simpleMath.expo(num1, num2); - System.out.println(num1 + " to the power of " + num2 + " = " + result); - break; - case 7: - result = simpleMath.squareRoot(num1); - System.out.println("The square root of " + num1 + " is " + result); - break; - case 8: - result = simpleMath.inverse(num1); - if (num1 != 0) { - System.out.println("The inverse of " + num1 + " is " + result); - } else { - System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); - } - break; - case 9: - result = simpleMath.invertSign(num1); - if (num1 != 0) { - System.out.println("The invert of " + num1 + " is " + result); - } else { - System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); - } - break; - case 10: - System.out.println("The logarithm of " + num1 + " is " + result); - break; - case 11: - System.out.println("The sine of " + num1 + " is " + result); - break; - case 12: - System.out.println("The cosine of " + num1 + " is " + result); - break; - case 13: - System.out.println("The tangent of " + num1 + " is " + result); - break; - case 14: - System.out.println("The arcsine of " + num1 + " is " + result); - break; - case 15: - System.out.println("The arccosine of " + num1 + " is " + result); - break; - case 16: - System.out.println("The arctangent of " + num1 + " is " + result); - break; - default: - System.out.println("Your input was incorrect please type one of the following:\n" + - "1 for addition \n2 for subtraction\n3 for multiplication\n4 for division\n" + - "5 for squaring \n6 for exponent\n7 for square root\n8 for inverse\n" + - "9 for invert\n10 for logarithms\n11 for sine\n12 for cosine\n13 tan for tangent\n" + - "14 for arcsine\n15 for arccosine\n16 for arctangent"); - break; - } + } - } } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java new file mode 100644 index 00000000..9d66dee5 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java @@ -0,0 +1,38 @@ +package com.zipcodewilmington.scientificcalculator; +import java.lang.Math; +public class ScientificFunctions { + public static double sin(double a) { + double b = Math.toRadians(a); + return(Math.sin(b)); + } + public static double cos(double a) { + a = Math.toRadians(a); + return(Math.cos(a)); + } + public static double tan(double a) { + double b = Math.toRadians(a); + return(Math.tan(b)); + } + public static double asin(double a) { + a = Math.PI; + return(Math.asin(a)); + } + public static double acos(double a) { + a = Math.PI / 2; + a = Math.toRadians(a); + return(Math.acos(a)); + } + public static double atan(double a) { + a = Math.PI; + return(Math.atan(a)); + } + public static double toDegrees(double rad) { + return(Math.toDegrees(rad)); + } + public static int factorial(int n) { + int res = 1, i; + for(i =2; i<=n; i++) + res *=i; + return res; + } +} \ No newline at end of file diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/LogFunctionsTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/LogFunctionsTest.java new file mode 100644 index 00000000..f2e31f07 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/LogFunctionsTest.java @@ -0,0 +1,44 @@ +package com.zipcodewilmington.scientific_calculator; +import com.zipcodewilmington.scientificcalculator.LogFunctions; +import org.junit.Assert; + +public class LogFunctionsTest { + @org.junit.Before + public void setUp() throws Exception { + } + @org.junit.After + public void tearDown() throws Exception{ + } + @org.junit.Test + public void testLogFunctionsLog(){ + LogFunctions log1 = new LogFunctions(); + Assert.assertEquals(0.7781512503836436, log1.log(6), 0.01); + Assert.assertEquals(1.65321251378, log1.log(45), 0.01); + Assert.assertEquals(-0.5376020021, log1.log(0.29), 0.01); + Assert.assertEquals(0.19865708695, log1.log(1.58), 0.01); + } + @org.junit.Test + public void testLogFunctionsInverseLog(){ + LogFunctions inverse1 = new LogFunctions(); + Assert.assertEquals(10000, inverse1.inverseLog(4), 0.01); + Assert.assertEquals(1.58489319246, inverse1.inverseLog(0.2), 0.01); + Assert.assertEquals(1.20226443462, inverse1.inverseLog(0.08), 0.01); + Assert.assertEquals(15.8489319246, inverse1.inverseLog(1.2), 0.01); + } + @org.junit.Test + public void testLogFunctionsNaturalLog() { + LogFunctions natLog1 = new LogFunctions(); + Assert.assertEquals(2.99573227355, natLog1.naturalLog(20), 0.01); + Assert.assertEquals(-1.38629436112, natLog1.naturalLog(0.25), 0.01); + Assert.assertEquals(1.5260563035, natLog1.naturalLog(4.6), 0.01); + Assert.assertEquals(-0.22314355131, natLog1.naturalLog(0.8), 0.01); + } + @org.junit.Test + public void testLogFunctionsInverseNaturalLog() { + LogFunctions invNatLog1 = new LogFunctions(); + Assert.assertEquals(1.10517091808, invNatLog1.inverseNatutalLog(0.1), 0.01); + Assert.assertEquals(1.34985880758, invNatLog1.inverseNatutalLog(0.3), 0.01); + Assert.assertEquals(1202604.28416, invNatLog1.inverseNatutalLog(14), 0.01); + Assert.assertEquals(11.0231763806, invNatLog1.inverseNatutalLog(2.4), 0.01); + } +} diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestScientificFunctions.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestScientificFunctions.java new file mode 100644 index 00000000..096973d1 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestScientificFunctions.java @@ -0,0 +1,67 @@ +package com.zipcodewilmington.scientific_calculator; +import org.junit.Assert; +import com.zipcodewilmington.scientificcalculator.ScientificFunctions; +public class TestScientificFunctions { + @org.junit.Before + public void setup()throws Exception { + } + @org.junit.After + public void tearDown() throws Exception{ + } + @org.junit.Test + public void TestScientificFunctionsSin() { + ScientificFunctions sin1 = new ScientificFunctions(); + Assert.assertEquals(0.49, sin1.sin(30), 0.01); + Assert.assertEquals(0.71, sin1.sin(45), 0.01); + Assert.assertEquals(1.00, sin1.sin(90), 0.01); + } + @org.junit.Test + public void TestScientificFunctionsCos() { + ScientificFunctions cos1 = new ScientificFunctions(); + Assert.assertEquals(0.64, cos1.cos(50), 0.01); + Assert.assertEquals(0.99, cos1.cos(5), 0.01); + Assert.assertEquals(0.98, cos1.cos(10), 0.01); + } + @org.junit.Test + public void TestScientificFunctionsTan() { + ScientificFunctions tan1 = new ScientificFunctions(); + Assert.assertEquals(0.08, tan1.tan(5.00), 0.01); + Assert.assertEquals(0.17, tan1.tan(10.00), 0.01); + Assert.assertEquals(0.16, tan1.tan(9.00), 0.02); + } + @org.junit.Test + public void TestScientificFunctionsAsin() { + ScientificFunctions asin1 = new ScientificFunctions(); + Assert.assertEquals(1.57, Math.asin(1.00), 0.01); + Assert.assertEquals(-0.52, Math.asin(-0.50), 0.01); + Assert.assertEquals(0.52, Math.asin(0.50), 0.01); + } + @org.junit.Test + public void TestScientificFunctionsAcos() { + ScientificFunctions acos1 = new ScientificFunctions(); + Assert.assertEquals(1.54, acos1.acos(1), 0.01); + Assert.assertEquals(1.54, acos1.acos(-1), 0.01); + Assert.assertEquals(0.99, acos1.cos(-0.5), 0.01); + } + @org.junit.Test + public void TestScientificFunctionsAtan() { + ScientificFunctions atan1 = new ScientificFunctions(); + Assert.assertEquals(1.26, atan1.atan(1), 0.01); + Assert.assertEquals(1.26, atan1.atan(-1), 0.01); + Assert.assertEquals(1.26, atan1.atan(0), 0.01); + } + @org.junit.Test + public void TestScientificFunctionsConvert() { + ScientificFunctions toDegrees1 = new ScientificFunctions(); + Assert.assertEquals(57.29, toDegrees1.toDegrees(1), 0.01); + Assert.assertEquals(114.59, toDegrees1.toDegrees(2), 0.01); + Assert.assertEquals(171.88, toDegrees1.toDegrees(3), 0.01); + } + @org.junit.Test + public void TestFactorial() { + ScientificFunctions factorial1 = new ScientificFunctions(); + Assert.assertEquals(120, factorial1.factorial(5), 0.01); + Assert.assertEquals(6, factorial1.factorial(3), 0.01); + Assert.assertEquals(40320, factorial1.factorial(8), 0.01); + } +} \ No newline at end of file From 880e3fab3fc531aeb0b8e57a22ff31ae491ec8ce Mon Sep 17 00:00:00 2001 From: Ben Coon Date: Mon, 21 Oct 2019 01:35:54 -0400 Subject: [PATCH 12/15] Working Interface. Some options still unavailable. --- .../scientificcalculator/Console.java | 7 + .../scientificcalculator/LogFunctions.java | 2 +- .../scientificcalculator/MainApplication.java | 310 +++++++++++++----- .../ScientificFunctions.java | 2 +- .../scientificcalculator/Settings.java | 6 - .../scientificcalculator/SwitchDisplay.java | 2 + .../LogFunctionsTest.java | 9 +- 7 files changed, 235 insertions(+), 103 deletions(-) delete mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/Settings.java diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index 37e8b965..dc7e62f8 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -15,6 +15,13 @@ 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 Integer getIntegerInput(String prompt) { Scanner scanner = new Scanner(System.in); println(prompt); diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/LogFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/LogFunctions.java index 028072f2..355b5941 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/LogFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/LogFunctions.java @@ -13,7 +13,7 @@ public Double naturalLog(double num1) { return Math.log(num1); } - public Double inverseNatutalLog(double num1) { + public Double inverseNaturalLog(double num1) { return Math.pow(2.71828182846, num1); } } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 7b1e27f1..117ee137 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -7,105 +7,233 @@ public class MainApplication { public static void main(String[] args) { - SimpleMath simpleMath = new SimpleMath(); - - double result = 1.0; - - Console.println("Welcome to my calculator!\n" + - "1 for addition \n2 for subtraction\n3 for multiplication\n4 for division\n" + - "5 for squaring \n6 for exponent\n7 for square root\n8 for inverse\n" + - "9 for invert\n10 for logarithms\n11 for sine\n12 for cosine\n13 tan for tangent\n"); - - Integer operation = Console.getIntegerInput("Enter the operation you would like to perform."); - Double num1 = Console.getDoubleInput("Enter your first number."); - - switch (operation) { - case 1: - Double num2 = Console.getDoubleInput("Enter your second."); - result = simpleMath.add(num1, num2); - System.out.println(num1 + " + " + num2 + " = " + result); - break; - case 2: - num2 = Console.getDoubleInput("Enter your second number."); - result = simpleMath.subtract(num1, num2); - System.out.println(num1 + " - " + num2 + " = " + result); - break; - case 3: - num2 = Console.getDoubleInput("Enter your second number."); - result = simpleMath.multiplication(num1, num2); - System.out.println(num1 + " x " + num2 + " = " + result); - break; - case 4: - num2 = Console.getDoubleInput("Enter your second number."); - if (num2 != 0) { - result = simpleMath.division(num1, num2); - System.out.println(num1 + " / " + num2 + " = " + result); + Integer operation; + Integer choice; + Integer choice2; + Double result; + Double num1 = 1.0; + Boolean binary; + Boolean octal; + Boolean hex; + Boolean decimal; + Boolean degrees; + Boolean radians; + + + SimpleMath simpleMath = new SimpleMath(); + LogFunctions logFunctions = new LogFunctions(); + ScientificFunctions scientificFunctions = new ScientificFunctions(); + SwitchDisplay switchDisplay = new SwitchDisplay(); + + Console.println("Welcome to my calculator!\n"); + + do { + Console.println("Please type one of the following options:\n" + + "1 = switchDisplay to change calculator to Binary, Octal, Decimal (normal), or Hexadecimal.\n" + + "2 = switchUnits to change between radians and degrees.\n" + + "3 = turn calculator off completely.\n" + + "4 = the calculator cause.... that's really what you need.\n"); + choice = Console.getIntegerInput("Enter the choice you would like to make."); + + if (choice == 1) { + Console.println("Pick one of the following please:\n"); + + do { + Console.println( "1 = Binary\n" + + "2 = Octal\n" + + "3 = Decimal\n" + + "4 = Hex\n"); + choice2 = Console.getIntegerInput(""); + if (choice2 == 1) { + binary = true; + octal = false; + decimal = false; + hex = false; + } else if (choice2 == 2) { + binary = false; + octal = true; + decimal = false; + hex = false; + } else if (choice2 == 3) { + binary = false; + octal = false; + decimal = true; + hex = false; + } else if (choice2 == 4) { + binary = false; + octal = false; + decimal = false; + hex = true; } else { - System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); + choice2 = 5; + Console.println("You have entered something incorrectly"); } - break; - case 5: - result = simpleMath.square(num1); - System.out.println(num1 + " squared is " + result); - break; - case 6: - num2 = Console.getDoubleInput("Enter your second number."); - result = simpleMath.expo(num1, num2); - System.out.println(num1 + " to the power of " + num2 + " = " + result); - break; - case 7: - result = simpleMath.squareRoot(num1); - System.out.println("The square root of " + num1 + " is " + result); - break; - case 8: - result = simpleMath.inverse(num1); - if (num1 != 0) { - System.out.println("The inverse of " + num1 + " is " + result); + } while (choice2 != 1 && choice2 != 2 && choice2 != 3 && choice2 != 4); + + } else if (choice == 2) { + + Console.println("Pick one of the following please:\n"); + do { + Console.println( "1 = Radians\n" + + "2 = Degrees\n"); + choice2 = Console.getIntegerInput(""); + if (choice2 == 1) { + radians = true; + degrees = false; + } else if (choice2 == 2) { + radians = false; + degrees = true; } else { - System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); + Console.println("You have entered something incorrectly"); } - break; - case 9: - result = simpleMath.invertSign(num1); - if (num1 != 0) { - System.out.println("The invert of " + num1 + " is " + result); - } else { - System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); + } while (choice2 != 1 && choice2 != 2); + + } else if (choice == 3) { + + Console.println("SHUTTING DOOOWWNNNNNN!!!!!!"); + + } else if (choice == 4) { + Console.println("0 will exit you out of the Calculator!!!!\n" + + "1 for addition 2 for subtraction\n" + + "3 for multiplication 4 for division\n" + + "5 for squaring 6 for exponent\n" + + "7 for square root 8 for inverse\n" + + "9 for invert 10 for logarithms\n" + + "11 for natural logarithms 12 for inverse logarithms\n" + + "13 for inverse natural logarithms 14 for sine\n" + + "15 for cosine 16 for tangent\n" + + "17 for arcsine 18 for arccosine\n" + + "19 for arctangent 20 for factorial\n" + + "Any other number for HELLLPPPPPPP"); + + do { + + operation = Console.getIntegerInput("Enter the operation you would like to perform."); + if (operation != 0 ) { + num1 = Console.getDoubleInput("Enter your first number."); } - break; - case 10: - System.out.println("The logarithm of " + num1 + " is " + result); - break; - case 11: - System.out.println("The sine of " + num1 + " is " + result); - break; - case 12: - System.out.println("The cosine of " + num1 + " is " + result); - break; - case 13: - System.out.println("The tangent of " + num1 + " is " + result); - break; - case 14: - System.out.println("The arcsine of " + num1 + " is " + result); - break; - case 15: - System.out.println("The arccosine of " + num1 + " is " + result); - break; - case 16: - System.out.println("The arctangent of " + num1 + " is " + result); - break; - default: - System.out.println("Your input was incorrect please type one of the following:\n" + - "1 for addition \n2 for subtraction\n3 for multiplication\n4 for division\n" + - "5 for squaring \n6 for exponent\n7 for square root\n8 for inverse\n" + - "9 for invert\n10 for logarithms\n11 for sine\n12 for cosine\n13 tan for tangent\n" + - "14 for arcsine\n15 for arccosine\n16 for arctangent"); - break; - } + switch (operation) { + case 1: + Double num2 = Console.getDoubleInput("Enter your second number."); + result = simpleMath.add(num1, num2); + System.out.println(num1 + " + " + num2 + " = " + result); + break; + case 2: + num2 = Console.getDoubleInput("Enter your second number."); + result = simpleMath.subtract(num1, num2); + System.out.println(num1 + " - " + num2 + " = " + result); + break; + case 3: + num2 = Console.getDoubleInput("Enter your second number."); + result = simpleMath.multiplication(num1, num2); + System.out.println(num1 + " x " + num2 + " = " + result); + break; + case 4: + num2 = Console.getDoubleInput("Enter your second number."); + if (num2 != 0) { + result = simpleMath.division(num1, num2); + System.out.println(num1 + " / " + num2 + " = " + result); + } else { + System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); + } + break; + case 5: + result = simpleMath.square(num1); + System.out.println(num1 + " squared is " + result); + break; + case 6: + num2 = Console.getDoubleInput("Enter your second number."); + result = simpleMath.expo(num1, num2); + System.out.println(num1 + " to the power of " + num2 + " = " + result); + break; + case 7: + result = simpleMath.squareRoot(num1); + System.out.println("The square root of " + num1 + " is " + result); + break; + case 8: + result = simpleMath.inverse(num1); + if (num1 != 0) { + System.out.println("The inverse of " + num1 + " is " + result); + } else { + System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); + } + break; + case 9: + result = simpleMath.invertSign(num1); + if (num1 != 0) { + System.out.println("The invert of " + num1 + " is " + result); + } else { + System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); + } + break; + case 10: + result = logFunctions.log(num1); + System.out.println("The logarithm of " + num1 + " is " + result); + break; + case 11: + result = logFunctions.naturalLog(num1); + System.out.println("The natural logarithm of " + num1 + " is " + result); + break; + case 12: + result = logFunctions.inverseLog(num1); + System.out.println("The inverse logarithm of " + num1 + " is " + result); + break; + case 13: + result = logFunctions.inverseNaturalLog(num1); + System.out.println("The inverse natural logarithm of " + num1 + " is " + result); + case 14: + result = scientificFunctions.sin(num1); + System.out.println("The sine of " + num1 + " is " + result); + break; + case 15: + result = scientificFunctions.cos(num1); + System.out.println("The cosine of " + num1 + " is " + result); + break; + case 16: + result = scientificFunctions.tan(num1); + System.out.println("The tangent of " + num1 + " is " + result); + break; + case 17: + result = scientificFunctions.asin(num1); + System.out.println("The arcsine of " + num1 + " is " + result); + break; + case 18: + result = scientificFunctions.acos(num1); + System.out.println("The arccosine of " + num1 + " is " + result); + break; + case 19: + result = scientificFunctions.atan(num1); + System.out.println("The arctangent of " + num1 + " is " + result); + break; + case 20: + result = scientificFunctions.factorial(num1); + System.out.println("The factorial of " + num1 + " is " + result); + break; + default: + System.out.println("Your input was incorrect please type one of the following:\n" + + "0 will exit you out of the Calculator!!!!\n" + + "1 for addition 2 for subtraction\n" + + "3 for multiplication 4 for division\n" + + "5 for squaring 6 for exponent\n" + + "7 for square root 8 for inverse\n" + + "9 for invert 10 for logarithms\n" + + "11 for natural logarithms 12 for inverse logarithms\n" + + "13 for inverse natural logarithms 14 for sine\n" + + "15 for cosine 16 for tangent\n" + + "17 for arcsine 18 for arccosine\n" + + "19 for arctangent 20 for factorial\n"); + break; + } - } + } while (operation != 0); + } else { + choice = 5; + Console.println("SOMETHING WROOoNNNNNGGGGgggggg!!!!"); + } + } while (choice != 3); + } } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java index 9d66dee5..b6a1db5d 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java @@ -29,7 +29,7 @@ public static double atan(double a) { public static double toDegrees(double rad) { return(Math.toDegrees(rad)); } - public static int factorial(int n) { + public static double factorial(double n) { int res = 1, i; for(i =2; i<=n; i++) res *=i; diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Settings.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Settings.java deleted file mode 100644 index 1db04914..00000000 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Settings.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.zipcodewilmington.scientificcalculator; - -public class Settings { - - -} diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java index b6c0c22b..8c00cb6f 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java @@ -13,6 +13,8 @@ public String toOctal(int num1){ public String toHex(int num1){ return Integer.toHexString(num1); } + + } diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/LogFunctionsTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/LogFunctionsTest.java index f2e31f07..338d62c9 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/LogFunctionsTest.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/LogFunctionsTest.java @@ -3,6 +3,7 @@ import org.junit.Assert; public class LogFunctionsTest { + @org.junit.Before public void setUp() throws Exception { } @@ -36,9 +37,9 @@ public void testLogFunctionsNaturalLog() { @org.junit.Test public void testLogFunctionsInverseNaturalLog() { LogFunctions invNatLog1 = new LogFunctions(); - Assert.assertEquals(1.10517091808, invNatLog1.inverseNatutalLog(0.1), 0.01); - Assert.assertEquals(1.34985880758, invNatLog1.inverseNatutalLog(0.3), 0.01); - Assert.assertEquals(1202604.28416, invNatLog1.inverseNatutalLog(14), 0.01); - Assert.assertEquals(11.0231763806, invNatLog1.inverseNatutalLog(2.4), 0.01); + Assert.assertEquals(1.10517091808, invNatLog1.inverseNaturalLog(0.1), 0.01); + Assert.assertEquals(1.34985880758, invNatLog1.inverseNaturalLog(0.3), 0.01); + Assert.assertEquals(1202604.28416, invNatLog1.inverseNaturalLog(14), 0.01); + Assert.assertEquals(11.0231763806, invNatLog1.inverseNaturalLog(2.4), 0.01); } } From 4dd86dd0dda5c0eb536b95eaaae5bce745889e06 Mon Sep 17 00:00:00 2001 From: Ben Coon Date: Mon, 21 Oct 2019 03:38:49 -0400 Subject: [PATCH 13/15] It runs but can't get switchUnits and switchDisplay working --- .../scientificcalculator/MainApplication.java | 123 +++++++++--------- .../ScientificFunctions.java | 18 ++- .../scientificcalculator/SwitchDisplay.java | 18 ++- 3 files changed, 93 insertions(+), 66 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 117ee137..ed981aed 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -9,15 +9,11 @@ public static void main(String[] args) { Integer operation; Integer choice; - Integer choice2; - Double result; + Integer choice2 = 1; + Integer choice3; + String result; Double num1 = 1.0; - Boolean binary; - Boolean octal; - Boolean hex; - Boolean decimal; - Boolean degrees; - Boolean radians; + SimpleMath simpleMath = new SimpleMath(); @@ -43,30 +39,33 @@ public static void main(String[] args) { "2 = Octal\n" + "3 = Decimal\n" + "4 = Hex\n"); + choice2 = Console.getIntegerInput(""); - if (choice2 == 1) { - binary = true; - octal = false; - decimal = false; - hex = false; - } else if (choice2 == 2) { - binary = false; - octal = true; - decimal = false; - hex = false; - } else if (choice2 == 3) { - binary = false; - octal = false; - decimal = true; - hex = false; - } else if (choice2 == 4) { - binary = false; - octal = false; - decimal = false; - hex = true; - } else { - choice2 = 5; - Console.println("You have entered something incorrectly"); + + switch (choice2) { + + case 1: + switchDisplay.binary = true; + switchDisplay.octal = false; + switchDisplay.hex = false; + break; + case 2: + switchDisplay.binary = false; + switchDisplay.octal = true; + switchDisplay.hex = false; + break; + case 3: + switchDisplay.binary = false; + switchDisplay.octal = false; + switchDisplay.hex = false; + break; + case 4: + switchDisplay.binary = false; + switchDisplay.octal = false; + switchDisplay.hex = true; + default: + choice2 = 5; + Console.println("You have entered something incorrectly"); } } while (choice2 != 1 && choice2 != 2 && choice2 != 3 && choice2 != 4); @@ -76,20 +75,19 @@ public static void main(String[] args) { do { Console.println( "1 = Radians\n" + "2 = Degrees\n"); - choice2 = Console.getIntegerInput(""); - if (choice2 == 1) { - radians = true; - degrees = false; - } else if (choice2 == 2) { - radians = false; - degrees = true; + choice3 = Console.getIntegerInput(""); + if (choice3 == 1) { + scientificFunctions.degrees = true; + scientificFunctions.degrees = false; + } else if (choice3 == 2) { + scientificFunctions.radians = false; + scientificFunctions.degrees = true; } else { Console.println("You have entered something incorrectly"); } - } while (choice2 != 1 && choice2 != 2); + } while (choice3 != 1 && choice3 != 2); } else if (choice == 3) { - Console.println("SHUTTING DOOOWWNNNNNN!!!!!!"); } else if (choice == 4) { @@ -104,7 +102,7 @@ public static void main(String[] args) { "15 for cosine 16 for tangent\n" + "17 for arcsine 18 for arccosine\n" + "19 for arctangent 20 for factorial\n" + - "Any other number for HELLLPPPPPPP"); + "Any other number for HELLLPPPPPPP\n\n\n"); do { @@ -116,43 +114,43 @@ public static void main(String[] args) { switch (operation) { case 1: Double num2 = Console.getDoubleInput("Enter your second number."); - result = simpleMath.add(num1, num2); + result = switchDisplay.toDisplay(simpleMath.add(num1, num2)); System.out.println(num1 + " + " + num2 + " = " + result); break; case 2: num2 = Console.getDoubleInput("Enter your second number."); - result = simpleMath.subtract(num1, num2); + result = switchDisplay.toDisplay(simpleMath.subtract(num1, num2)); System.out.println(num1 + " - " + num2 + " = " + result); break; case 3: num2 = Console.getDoubleInput("Enter your second number."); - result = simpleMath.multiplication(num1, num2); + result = switchDisplay.toDisplay(simpleMath.multiplication(num1, num2)); System.out.println(num1 + " x " + num2 + " = " + result); break; case 4: num2 = Console.getDoubleInput("Enter your second number."); if (num2 != 0) { - result = simpleMath.division(num1, num2); + result = switchDisplay.toDisplay(simpleMath.division(num1, num2)); System.out.println(num1 + " / " + num2 + " = " + result); } else { System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); } break; case 5: - result = simpleMath.square(num1); + result = switchDisplay.toDisplay(simpleMath.square(num1)); System.out.println(num1 + " squared is " + result); break; case 6: num2 = Console.getDoubleInput("Enter your second number."); - result = simpleMath.expo(num1, num2); + result = switchDisplay.toDisplay(simpleMath.expo(num1, num2)); System.out.println(num1 + " to the power of " + num2 + " = " + result); break; case 7: - result = simpleMath.squareRoot(num1); + result = switchDisplay.toDisplay(simpleMath.squareRoot(num1)); System.out.println("The square root of " + num1 + " is " + result); break; case 8: - result = simpleMath.inverse(num1); + result = switchDisplay.toDisplay(simpleMath.inverse(num1)); if (num1 != 0) { System.out.println("The inverse of " + num1 + " is " + result); } else { @@ -160,7 +158,7 @@ public static void main(String[] args) { } break; case 9: - result = simpleMath.invertSign(num1); + result = switchDisplay.toDisplay(simpleMath.invertSign(num1)); if (num1 != 0) { System.out.println("The invert of " + num1 + " is " + result); } else { @@ -168,46 +166,46 @@ public static void main(String[] args) { } break; case 10: - result = logFunctions.log(num1); + result = switchDisplay.toDisplay(logFunctions.log(num1)); System.out.println("The logarithm of " + num1 + " is " + result); break; case 11: - result = logFunctions.naturalLog(num1); + result = switchDisplay.toDisplay(logFunctions.naturalLog(num1)); System.out.println("The natural logarithm of " + num1 + " is " + result); break; case 12: - result = logFunctions.inverseLog(num1); + result = switchDisplay.toDisplay(logFunctions.inverseLog(num1)); System.out.println("The inverse logarithm of " + num1 + " is " + result); break; case 13: - result = logFunctions.inverseNaturalLog(num1); + result = switchDisplay.toDisplay(logFunctions.inverseNaturalLog(num1)); System.out.println("The inverse natural logarithm of " + num1 + " is " + result); case 14: - result = scientificFunctions.sin(num1); + result = switchDisplay.toDisplay(scientificFunctions.sin(scientificFunctions.switchUnits(num1))); System.out.println("The sine of " + num1 + " is " + result); break; case 15: - result = scientificFunctions.cos(num1); + result = switchDisplay.toDisplay(scientificFunctions.cos(scientificFunctions.switchUnits(num1))); System.out.println("The cosine of " + num1 + " is " + result); break; case 16: - result = scientificFunctions.tan(num1); + result = switchDisplay.toDisplay(scientificFunctions.tan(scientificFunctions.switchUnits(num1))); System.out.println("The tangent of " + num1 + " is " + result); break; case 17: - result = scientificFunctions.asin(num1); + result = switchDisplay.toDisplay(scientificFunctions.asin(scientificFunctions.switchUnits(num1))); System.out.println("The arcsine of " + num1 + " is " + result); break; case 18: - result = scientificFunctions.acos(num1); + result = switchDisplay.toDisplay(scientificFunctions.acos(scientificFunctions.switchUnits(num1))); System.out.println("The arccosine of " + num1 + " is " + result); break; case 19: - result = scientificFunctions.atan(num1); + result = switchDisplay.toDisplay(scientificFunctions.atan(scientificFunctions.switchUnits(num1))); System.out.println("The arctangent of " + num1 + " is " + result); break; case 20: - result = scientificFunctions.factorial(num1); + result = switchDisplay.toDisplay(scientificFunctions.factorial(num1)); System.out.println("The factorial of " + num1 + " is " + result); break; default: @@ -222,7 +220,8 @@ public static void main(String[] args) { "13 for inverse natural logarithms 14 for sine\n" + "15 for cosine 16 for tangent\n" + "17 for arcsine 18 for arccosine\n" + - "19 for arctangent 20 for factorial\n"); + "19 for arctangent 20 for factorial\n" + + "Any other number for HELLLPPPPPPP"); break; } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java index b6a1db5d..dba148fb 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java @@ -1,6 +1,10 @@ package com.zipcodewilmington.scientificcalculator; import java.lang.Math; public class ScientificFunctions { + + public Boolean radians; + public Boolean degrees; + public static double sin(double a) { double b = Math.toRadians(a); return(Math.sin(b)); @@ -26,13 +30,21 @@ public static double atan(double a) { a = Math.PI; return(Math.atan(a)); } - public static double toDegrees(double rad) { - return(Math.toDegrees(rad)); - } public static double factorial(double n) { int res = 1, i; for(i =2; i<=n; i++) res *=i; return res; } + public static double toDegrees(double rad) { + return(Math.toDegrees(rad)); + } + public double switchUnits (double num1) { + if (degrees = false) { + double num2 = toDegrees(num1); + return num2; + } else { + return num1; + } + } } \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java index 8c00cb6f..75ca0dc1 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java @@ -2,6 +2,10 @@ public class SwitchDisplay { + public Boolean binary; + public Boolean octal; + public Boolean hex; + public String toBinary(int num1){ return Integer.toBinaryString(num1); } @@ -14,7 +18,19 @@ public String toHex(int num1){ return Integer.toHexString(num1); } - + public String toDisplay(double num1) { + + int num2 = (int) Math.round(num1); + if (binary = false) { + return toBinary(num2); + } else if (octal = false) { + return toOctal(num2); + } else if (hex = false) { + return toHex(num2); + } else { + return String.valueOf(num1); + } + } } From 2da56df0a4deea873a5c6d6365a4a8af6d170c5d Mon Sep 17 00:00:00 2001 From: Ben Coon Date: Mon, 21 Oct 2019 16:15:28 -0400 Subject: [PATCH 14/15] Working Calc. No recall function --- .../scientificcalculator/MainApplication.java | 89 +++++++------------ .../ScientificFunctions.java | 5 +- .../scientificcalculator/SwitchDisplay.java | 8 +- 3 files changed, 41 insertions(+), 61 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index ed981aed..7907be6e 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -9,13 +9,13 @@ public static void main(String[] args) { Integer operation; Integer choice; - Integer choice2 = 1; - Integer choice3; + Integer choice3 = 1; String result; Double num1 = 1.0; + Integer display = 4; - + SimpleMath simpleMath = new SimpleMath(); LogFunctions logFunctions = new LogFunctions(); ScientificFunctions scientificFunctions = new ScientificFunctions(); @@ -37,37 +37,16 @@ public static void main(String[] args) { do { Console.println( "1 = Binary\n" + "2 = Octal\n" + - "3 = Decimal\n" + - "4 = Hex\n"); - - choice2 = Console.getIntegerInput(""); + "3 = Hex\n" + + "4 = Decimal\n"); - switch (choice2) { + display = Console.getIntegerInput("\n"); - case 1: - switchDisplay.binary = true; - switchDisplay.octal = false; - switchDisplay.hex = false; - break; - case 2: - switchDisplay.binary = false; - switchDisplay.octal = true; - switchDisplay.hex = false; - break; - case 3: - switchDisplay.binary = false; - switchDisplay.octal = false; - switchDisplay.hex = false; - break; - case 4: - switchDisplay.binary = false; - switchDisplay.octal = false; - switchDisplay.hex = true; - default: - choice2 = 5; - Console.println("You have entered something incorrectly"); + if (display != 1 && display != 2 && display != 3 && display != 4){ + Console.println("You have entered something incorrectly"); } - } while (choice2 != 1 && choice2 != 2 && choice2 != 3 && choice2 != 4); + + } while (display != 1 && display != 2 && display != 3 && display != 4); } else if (choice == 2) { @@ -76,7 +55,7 @@ public static void main(String[] args) { Console.println( "1 = Radians\n" + "2 = Degrees\n"); choice3 = Console.getIntegerInput(""); - if (choice3 == 1) { + /*if (choice3 == 1) { scientificFunctions.degrees = true; scientificFunctions.degrees = false; } else if (choice3 == 2) { @@ -84,7 +63,7 @@ public static void main(String[] args) { scientificFunctions.degrees = true; } else { Console.println("You have entered something incorrectly"); - } + }*/ } while (choice3 != 1 && choice3 != 2); } else if (choice == 3) { @@ -114,43 +93,43 @@ public static void main(String[] args) { switch (operation) { case 1: Double num2 = Console.getDoubleInput("Enter your second number."); - result = switchDisplay.toDisplay(simpleMath.add(num1, num2)); + result = switchDisplay.toDisplay(simpleMath.add(num1, num2), display); System.out.println(num1 + " + " + num2 + " = " + result); break; case 2: num2 = Console.getDoubleInput("Enter your second number."); - result = switchDisplay.toDisplay(simpleMath.subtract(num1, num2)); + result = switchDisplay.toDisplay(simpleMath.subtract(num1, num2), display); System.out.println(num1 + " - " + num2 + " = " + result); break; case 3: num2 = Console.getDoubleInput("Enter your second number."); - result = switchDisplay.toDisplay(simpleMath.multiplication(num1, num2)); + result = switchDisplay.toDisplay(simpleMath.multiplication(num1, num2), display); System.out.println(num1 + " x " + num2 + " = " + result); break; case 4: num2 = Console.getDoubleInput("Enter your second number."); if (num2 != 0) { - result = switchDisplay.toDisplay(simpleMath.division(num1, num2)); + result = switchDisplay.toDisplay(simpleMath.division(num1, num2), display); System.out.println(num1 + " / " + num2 + " = " + result); } else { System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); } break; case 5: - result = switchDisplay.toDisplay(simpleMath.square(num1)); + result = switchDisplay.toDisplay(simpleMath.square(num1), display); System.out.println(num1 + " squared is " + result); break; case 6: num2 = Console.getDoubleInput("Enter your second number."); - result = switchDisplay.toDisplay(simpleMath.expo(num1, num2)); + result = switchDisplay.toDisplay(simpleMath.expo(num1, num2), display); System.out.println(num1 + " to the power of " + num2 + " = " + result); break; case 7: - result = switchDisplay.toDisplay(simpleMath.squareRoot(num1)); + result = switchDisplay.toDisplay(simpleMath.squareRoot(num1), display); System.out.println("The square root of " + num1 + " is " + result); break; case 8: - result = switchDisplay.toDisplay(simpleMath.inverse(num1)); + result = switchDisplay.toDisplay(simpleMath.inverse(num1), display); if (num1 != 0) { System.out.println("The inverse of " + num1 + " is " + result); } else { @@ -158,7 +137,7 @@ public static void main(String[] args) { } break; case 9: - result = switchDisplay.toDisplay(simpleMath.invertSign(num1)); + result = switchDisplay.toDisplay(simpleMath.invertSign(num1), display); if (num1 != 0) { System.out.println("The invert of " + num1 + " is " + result); } else { @@ -166,46 +145,46 @@ public static void main(String[] args) { } break; case 10: - result = switchDisplay.toDisplay(logFunctions.log(num1)); + result = switchDisplay.toDisplay(logFunctions.log(num1), display); System.out.println("The logarithm of " + num1 + " is " + result); break; case 11: - result = switchDisplay.toDisplay(logFunctions.naturalLog(num1)); + result = switchDisplay.toDisplay(logFunctions.naturalLog(num1), display); System.out.println("The natural logarithm of " + num1 + " is " + result); break; case 12: - result = switchDisplay.toDisplay(logFunctions.inverseLog(num1)); + result = switchDisplay.toDisplay(logFunctions.inverseLog(num1), display); System.out.println("The inverse logarithm of " + num1 + " is " + result); break; case 13: - result = switchDisplay.toDisplay(logFunctions.inverseNaturalLog(num1)); + result = switchDisplay.toDisplay(logFunctions.inverseNaturalLog(num1), display); System.out.println("The inverse natural logarithm of " + num1 + " is " + result); case 14: - result = switchDisplay.toDisplay(scientificFunctions.sin(scientificFunctions.switchUnits(num1))); + result = switchDisplay.toDisplay(scientificFunctions.sin(scientificFunctions.switchUnits(num1, choice3)), display); System.out.println("The sine of " + num1 + " is " + result); break; case 15: - result = switchDisplay.toDisplay(scientificFunctions.cos(scientificFunctions.switchUnits(num1))); + result = switchDisplay.toDisplay(scientificFunctions.cos(scientificFunctions.switchUnits(num1, choice3)), display); System.out.println("The cosine of " + num1 + " is " + result); break; case 16: - result = switchDisplay.toDisplay(scientificFunctions.tan(scientificFunctions.switchUnits(num1))); + result = switchDisplay.toDisplay(scientificFunctions.tan(scientificFunctions.switchUnits(num1, choice3)), display); System.out.println("The tangent of " + num1 + " is " + result); break; case 17: - result = switchDisplay.toDisplay(scientificFunctions.asin(scientificFunctions.switchUnits(num1))); + result = switchDisplay.toDisplay(scientificFunctions.asin(scientificFunctions.switchUnits(num1, choice3)), display); System.out.println("The arcsine of " + num1 + " is " + result); break; case 18: - result = switchDisplay.toDisplay(scientificFunctions.acos(scientificFunctions.switchUnits(num1))); + result = switchDisplay.toDisplay(scientificFunctions.acos(scientificFunctions.switchUnits(num1, choice3)), display); System.out.println("The arccosine of " + num1 + " is " + result); break; case 19: - result = switchDisplay.toDisplay(scientificFunctions.atan(scientificFunctions.switchUnits(num1))); + result = switchDisplay.toDisplay(scientificFunctions.atan(scientificFunctions.switchUnits(num1, choice3)), display); System.out.println("The arctangent of " + num1 + " is " + result); break; case 20: - result = switchDisplay.toDisplay(scientificFunctions.factorial(num1)); + result = switchDisplay.toDisplay(scientificFunctions.factorial(num1), display); System.out.println("The factorial of " + num1 + " is " + result); break; default: @@ -221,7 +200,7 @@ public static void main(String[] args) { "15 for cosine 16 for tangent\n" + "17 for arcsine 18 for arccosine\n" + "19 for arctangent 20 for factorial\n" + - "Any other number for HELLLPPPPPPP"); + "Any other number for HELLLPPPPPPP\n\n\n"); break; } @@ -229,7 +208,7 @@ public static void main(String[] args) { } while (operation != 0); } else { choice = 5; - Console.println("SOMETHING WROOoNNNNNGGGGgggggg!!!!"); + Console.println("SOMETHING WROOoNNNNNGGGGgggggg!!!!\n"); } } while (choice != 3); } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java index dba148fb..52338d02 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java @@ -39,8 +39,9 @@ public static double factorial(double n) { public static double toDegrees(double rad) { return(Math.toDegrees(rad)); } - public double switchUnits (double num1) { - if (degrees = false) { + + public double switchUnits (double num1, int setter) { + if (setter == 1) { double num2 = toDegrees(num1); return num2; } else { diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java index 75ca0dc1..8b6ce5c2 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java @@ -18,14 +18,14 @@ public String toHex(int num1){ return Integer.toHexString(num1); } - public String toDisplay(double num1) { + public String toDisplay(double num1, int setter) { int num2 = (int) Math.round(num1); - if (binary = false) { + if (setter == 1) { return toBinary(num2); - } else if (octal = false) { + } else if (setter == 2) { return toOctal(num2); - } else if (hex = false) { + } else if (setter == 3) { return toHex(num2); } else { return String.valueOf(num1); From 55135de122aedd361f663c4469f3cdcf98bb5551 Mon Sep 17 00:00:00 2001 From: Ben Coon Date: Mon, 21 Oct 2019 17:02:32 -0400 Subject: [PATCH 15/15] As good as it's gonna GIT --- .../scientificcalculator/MainApplication.java | 9 --------- .../scientificcalculator/ScientificFunctions.java | 5 +++-- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 7907be6e..bbe49bf1 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -55,15 +55,6 @@ public static void main(String[] args) { Console.println( "1 = Radians\n" + "2 = Degrees\n"); choice3 = Console.getIntegerInput(""); - /*if (choice3 == 1) { - scientificFunctions.degrees = true; - scientificFunctions.degrees = false; - } else if (choice3 == 2) { - scientificFunctions.radians = false; - scientificFunctions.degrees = true; - } else { - Console.println("You have entered something incorrectly"); - }*/ } while (choice3 != 1 && choice3 != 2); } else if (choice == 3) { diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java index 52338d02..9d7ad6d2 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java @@ -10,8 +10,8 @@ public static double sin(double a) { return(Math.sin(b)); } public static double cos(double a) { - a = Math.toRadians(a); - return(Math.cos(a)); + double b = Math.toRadians(a); + return(Math.cos(b)); } public static double tan(double a) { double b = Math.toRadians(a); @@ -48,4 +48,5 @@ public double switchUnits (double num1, int setter) { return num1; } } + } \ No newline at end of file