From 17ec842d498af3226ff3240b851d31c0445e8d91 Mon Sep 17 00:00:00 2001 From: r-m-hufford Date: Sat, 27 Feb 2021 07:47:50 -0500 Subject: [PATCH 1/6] Created to test IntelliJ push --- .../scientificcalculator/calculatorOperator.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/calculatorOperator.java diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/calculatorOperator.java b/src/main/java/com/zipcodewilmington/scientificcalculator/calculatorOperator.java new file mode 100644 index 00000000..4b3070f1 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/calculatorOperator.java @@ -0,0 +1,4 @@ +package com.zipcodewilmington.scientificcalculator; + +public class calculatorOperator { +} From 9698e26fc2c1e2aa74912ca2b626571ac6c565b0 Mon Sep 17 00:00:00 2001 From: r-m-hufford Date: Sat, 27 Feb 2021 07:58:35 -0500 Subject: [PATCH 2/6] added power method --- .../scientificcalculator/calculatorOperator.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/calculatorOperator.java b/src/main/java/com/zipcodewilmington/scientificcalculator/calculatorOperator.java index 4b3070f1..cf7017ae 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/calculatorOperator.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/calculatorOperator.java @@ -1,4 +1,9 @@ package com.zipcodewilmington.scientificcalculator; public class calculatorOperator { + + public int power (int a, int b) { + int power = (int) Math.pow(a,b); + return power; + } } From 6602e690a82475b5573b5679bfbfb57cedf8269d Mon Sep 17 00:00:00 2001 From: r-m-hufford Date: Sat, 27 Feb 2021 11:46:02 -0500 Subject: [PATCH 3/6] all core operators --- pom.xml | 14 +++++ .../CalculatorOperator.java | 52 +++++++++++++++++++ .../calculatorOperator.java | 9 ---- .../TestMainApplication.java | 49 +++++++++++++++++ 4 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/CalculatorOperator.java delete mode 100644 src/main/java/com/zipcodewilmington/scientificcalculator/calculatorOperator.java diff --git a/pom.xml b/pom.xml index e7cb4f6b..7e3fbd55 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,20 @@ com.zipcodewilmington scientific_calculator 1.0-SNAPSHOT + + + org.junit.jupiter + junit-jupiter + RELEASE + test + + + junit + junit + 4.12 + test + + \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CalculatorOperator.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CalculatorOperator.java new file mode 100644 index 00000000..2deec897 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CalculatorOperator.java @@ -0,0 +1,52 @@ +package com.zipcodewilmington.scientificcalculator; + +public class CalculatorOperator { + + public static double addition (double a, double b) { + double addition = a + b; + return addition; + } + + public static double subtraction + (double a, double b) { + double subtraction = a - b; + return subtraction; + } + + public static double multiplication (double a, double b) { + double multiplication = a * b; + return multiplication; + } + + public static double division (double a, double b) { + double division = a / b; + return division; + } + + public static int square (int a) { + int square = (int) Math.pow(a,2); + return square; + } + + public static double squareRoot (int a) { + int squareRoot = (int) Math.sqrt(a); + return squareRoot; + } + + public static int exponents (int a, int b) { + int exponent = (int) Math.pow(a,b); + return exponent; + } + + public static double multiplicativeInverse (double a) { + double multiplicativeInverse = 1/a; + return multiplicativeInverse; + } + + public static int additiveInverse (int a) { + int additiveInverse = a * -1; + return additiveInverse; + } + +} + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/calculatorOperator.java b/src/main/java/com/zipcodewilmington/scientificcalculator/calculatorOperator.java deleted file mode 100644 index cf7017ae..00000000 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/calculatorOperator.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.zipcodewilmington.scientificcalculator; - -public class calculatorOperator { - - public int power (int a, int b) { - int power = (int) Math.pow(a,b); - return power; - } -} diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java index 94e8d987..0f2a1f30 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java @@ -1,7 +1,56 @@ package com.zipcodewilmington.scientific_calculator; +import com.zipcodewilmington.scientificcalculator.CalculatorOperator; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + + /** * Created by leon on 2/9/18. */ public class TestMainApplication { + @Test + public void addition() { + Assertions.assertEquals(6 , CalculatorOperator.addition(3, 3)); + } + + @Test + public void subtraction() { + Assertions.assertEquals(-1 , CalculatorOperator.subtraction(3, 4)); + } + + @Test + public void multiplication() { + Assertions.assertEquals(17 , CalculatorOperator.multiplication(17, 1)); + } + + @Test + public void division() { + Assertions.assertEquals(1 , CalculatorOperator.division(22, 22)); + } + + @Test + public void squareTest() { + Assertions.assertEquals(9 , CalculatorOperator.square(3)); + } + + @Test + public void squareRootTest() { + Assertions.assertEquals(5 , CalculatorOperator.squareRoot(25)); + } + + @Test + public void exponentsTest() { + Assertions.assertEquals(4 , CalculatorOperator.exponents(2,2)); + } + + @Test + public void multiplicativeInverseTest() { + Assertions.assertEquals(1 , CalculatorOperator.multiplicativeInverse(1)); + } + + @Test + public void additiveInverseTest() { + Assertions.assertEquals(4 , CalculatorOperator.additiveInverse(-4)); + } } From cb9af165c1d00791c3cc0128ff1710611da81853 Mon Sep 17 00:00:00 2001 From: r-m-hufford Date: Sat, 27 Feb 2021 12:42:58 -0500 Subject: [PATCH 4/6] update to console removes null point error --- .../scientificcalculator/CalculatorOperator.java | 16 ++++++++-------- .../scientificcalculator/Console.java | 10 ++++++++-- .../scientificcalculator/MainApplication.java | 5 +++++ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CalculatorOperator.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CalculatorOperator.java index 2deec897..89a053a9 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/CalculatorOperator.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CalculatorOperator.java @@ -23,18 +23,18 @@ public static double division (double a, double b) { return division; } - public static int square (int a) { - int square = (int) Math.pow(a,2); + public static double square (double a) { + double square = Math.pow(a,2); return square; } - public static double squareRoot (int a) { - int squareRoot = (int) Math.sqrt(a); + public static double squareRoot (double a) { + double squareRoot = Math.sqrt(a); return squareRoot; } - public static int exponents (int a, int b) { - int exponent = (int) Math.pow(a,b); + public static double exponents (double a, double b) { + double exponent = Math.pow(a,b); return exponent; } @@ -43,8 +43,8 @@ public static double multiplicativeInverse (double a) { return multiplicativeInverse; } - public static int additiveInverse (int a) { - int additiveInverse = a * -1; + public static double additiveInverse (double a) { + double additiveInverse = a * -1; return additiveInverse; } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index 83f0e97f..d3c6550b 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); + int userInput = scanner.nextInt(); + return userInput; } public static Double getDoubleInput(String prompt) { - return null; + Scanner scanner = new Scanner(System.in); + println(prompt); + double userInput = scanner.nextDouble(); + return userInput; } } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 5f421325..d16b9069 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -13,5 +13,10 @@ public static void main(String[] args) { 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 3ff87226b139faa65bbf30fa275b33627fe69f54 Mon Sep 17 00:00:00 2001 From: r-m-hufford Date: Sat, 27 Feb 2021 14:47:22 -0500 Subject: [PATCH 5/6] Core functionality. Four Functions. Tests Passed --- pom.xml | 12 +++++++++ .../scientificcalculator/MainApplication.java | 26 ++++++++++++++----- .../TestMainApplication.java | 11 ++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 7e3fbd55..3af9ec0b 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 + + 7 + 7 + + + + org.junit.jupiter diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index d16b9069..1887c9df 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -7,16 +7,30 @@ public class MainApplication { 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 i = Console.getDoubleInput("Enter a double"); 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); - - - } - -} + public static double calculator (String s, double i, double d) { + double result = 0; + switch (s) { + case "+": + result = CalculatorOperator.addition(i, d); + break; + case "-": + result = CalculatorOperator.subtraction(i, d); + break; + case "*": + result = CalculatorOperator.multiplication(i, d); + break; + case "/": + result = CalculatorOperator.division(i,d); + break; + } + return result; + } + } diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java index 0f2a1f30..c53f6a41 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java @@ -1,6 +1,7 @@ package com.zipcodewilmington.scientific_calculator; import com.zipcodewilmington.scientificcalculator.CalculatorOperator; +import com.zipcodewilmington.scientificcalculator.MainApplication; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -53,4 +54,14 @@ public void multiplicativeInverseTest() { public void additiveInverseTest() { Assertions.assertEquals(4 , CalculatorOperator.additiveInverse(-4)); } + + @Test + public void calculatorTest() { + Assertions.assertEquals(5.2 , MainApplication.calculator("+", 2.2, 3.0)); + Assertions.assertEquals(-1 , MainApplication.calculator("-", 2.0, 3.0)); + Assertions.assertEquals(6 , MainApplication.calculator("*", 2.0, 3.0)); + Assertions.assertEquals(4 , MainApplication.calculator("/", 12, 3)); + } + + } From 5ccda417fbb5419455c7b1c6e11fc69aef2a490b Mon Sep 17 00:00:00 2001 From: r-m-hufford Date: Sat, 27 Feb 2021 16:56:55 -0500 Subject: [PATCH 6/6] added commits --- .../scientificcalculator/CalculatorOperator.java | 2 ++ .../com/zipcodewilmington/scientificcalculator/Console.java | 2 ++ .../zipcodewilmington/scientificcalculator/MainApplication.java | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CalculatorOperator.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CalculatorOperator.java index 89a053a9..ebd33e0b 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/CalculatorOperator.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CalculatorOperator.java @@ -1,5 +1,7 @@ package com.zipcodewilmington.scientificcalculator; +//comments + public class CalculatorOperator { public static double addition (double a, double b) { diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index d3c6550b..282c1c9e 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -1,5 +1,7 @@ package com.zipcodewilmington.scientificcalculator; +// comments + import java.util.Scanner; /** diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 1887c9df..c3770264 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -1,5 +1,7 @@ package com.zipcodewilmington.scientificcalculator; +// comments + /** * Created by leon on 2/9/18. */