diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..824d9d57 Binary files /dev/null and b/.DS_Store differ diff --git a/pom.xml b/pom.xml index e7cb4f6b..ece71c64 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,20 @@ com.zipcodewilmington scientific_calculator 1.0-SNAPSHOT + + + junit + junit + 4.12 + test + + + org.junit.jupiter + junit-jupiter + RELEASE + test + + \ No newline at end of file diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 00000000..e153a0a2 Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/main/.DS_Store b/src/main/.DS_Store new file mode 100644 index 00000000..7bb43dbf Binary files /dev/null and b/src/main/.DS_Store differ diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store new file mode 100644 index 00000000..fb256c80 Binary files /dev/null and b/src/main/java/.DS_Store differ diff --git a/src/main/java/com/.DS_Store b/src/main/java/com/.DS_Store new file mode 100644 index 00000000..f318c66e Binary files /dev/null and b/src/main/java/com/.DS_Store differ diff --git a/src/main/java/com/zipcodewilmington/.DS_Store b/src/main/java/com/zipcodewilmington/.DS_Store new file mode 100644 index 00000000..2e00b410 Binary files /dev/null and b/src/main/java/com/zipcodewilmington/.DS_Store differ diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java new file mode 100644 index 00000000..05a5ade1 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java @@ -0,0 +1,327 @@ +package com.zipcodewilmington.scientificcalculator; +public class Calculator { + public Calculator() { + } + private double memory; + public void drawScreen(String d){ + Console.println(""); + Console.println("|------------------------------------------------|"); + Console.println("|Quit Clear Set M+ MC MRC |"); + Console.println("|------------------------------------------------|"); + Console.println(" Current Number: %s ",d); + Console.println("|------------------------------------------------|"); + Console.println("| Add Subtract Multiply Divide |"); + Console.println("| Square Square Root Exponential Inverse |"); + Console.println("| Log Log-1 Ln Ln-1 |"); + Console.println("| Sine Cosine Tangent Factorial |"); + Console.println("| Sine-1 Cosine-1 Tangent-1 Invert |"); + Console.println("| cToF fToC LBtoKG KGtoLB |"); + Console.println("| decToBinary decToOct decToHex |"); + Console.println("| octToBinary octToDec octToHex |"); + Console.println("| hexToBinary hexToOct hextoDec |"); + Console.println("| binaryToDec binaryToOct binaryToHex |"); + Console.println("| radToDeg degToRad |"); + Console.println("|------------------------------------------------|"); + } + public double performOperation(String op, double num1, double num2){ + double returnAns; + if(op.equalsIgnoreCase("add")){ + returnAns = this.addition(num1,num2); + } + else if(op.equalsIgnoreCase("subtract")){ + returnAns = this.subtraction(num1,num2); + } + else if(op.equalsIgnoreCase("multiply")){ + returnAns = this.multiply(num1, num2); + } + else if(op.equalsIgnoreCase("divide")){ + returnAns = this.divide(num1, num2); + } + else { + returnAns = this.exponential(num1, num2); + } + return returnAns; + } + public double performOperation(String op, double num){ + double returnAns; + if(op.equalsIgnoreCase("square")){ + returnAns = this.square(num); + } + else if(op.equalsIgnoreCase("square root")){ + returnAns = this.squareRoot(num); + } + else if(op.equalsIgnoreCase("inverse")){ + returnAns = this.inverse(num); + } + else if(op.equalsIgnoreCase("invert")){ + returnAns = this.invert(num); + } + else if(op.equalsIgnoreCase("sine")){ + returnAns = this.sine(num); + } + else if(op.equalsIgnoreCase("cosine")){ + returnAns = this.cosine(num); + } + else if(op.equalsIgnoreCase("tangent")){ + returnAns = this.tangent(num); + } + else if(op.equalsIgnoreCase("sine-1")){ + returnAns = this.inverseSine(num); + } + else if(op.equalsIgnoreCase("cosine-1")){ + returnAns = this.inverseCosine(num); + } + else if(op.equalsIgnoreCase("tangent-1")){ + returnAns = this.inverseTangent(num); + } + else if(op.equalsIgnoreCase("factorial")){ + returnAns = this.factorial(num); + } + else if(op.equalsIgnoreCase("log")){ + returnAns = this.log(num); + } + else if(op.equalsIgnoreCase("log-1")){ + returnAns = this.inverseLog(num); + } + else if(op.equalsIgnoreCase("ln")){ + returnAns = this.naturalLog(num); + } + else if(op.equalsIgnoreCase("ln-1")) { + returnAns = this.inverseNaturalLog(num); + } + else if(op.equalsIgnoreCase("lbToKg")){ + returnAns = this.convertLBtoKG(num); + } + else if(op.equalsIgnoreCase("kgtoLb")) { + returnAns = this.convertKGtoLB(num); + } + else if(op.equalsIgnoreCase("radtodeg")) { + returnAns = this.toDegrees(num); + } + else if(op.equalsIgnoreCase("degtorad")) { + returnAns = this.toRadians(num); + } + else if(op.equalsIgnoreCase("fToC")){ + returnAns = this.convertFtoC(num); + } + //catching convert C to F + else { + returnAns = this.convertCtoF(num); + } + return returnAns; + } + //store, recall, and clear memory + public double memoryUsage(String inputStr, double x) { + double memory = 0; + if (inputStr.equalsIgnoreCase("M+")) { + memory = this.calcMemory(x); + } else if (inputStr.equalsIgnoreCase("MC")){ + memory = 0; + } else if (inputStr.equalsIgnoreCase("MRC")) { + return memory; + } else { + memory = 0; + } + return memory; + } + //two variable operations + public double addition(double x, double y){ + double ans = x + y; + return ans; + } + public double subtraction(double x,double y){ + double ans = x - y; + return ans; + } + public double multiply(double x,double y){ + double ans = x * y; + return ans; + } + public double divide(double x,double y){ + double ans = x / y; + return ans; + } + public double exponential(double x,double y){ + double ans = Math.pow(x,y); + return ans; + } + //one variable operations + public double square(double x){ + double ans = Math.pow(x,2); + return ans; + } + public double squareRoot(double x){ + double ans = Math.sqrt(x); + return ans; + } + public double inverse(double x){ + double ans = (1 / x); + return ans; + } + public double invert(double x){ + double ans = (x * -1); + return ans; + } + public double sine(double x){ + double ans = Math.sin(x); + return ans; + } + public double cosine(double x){ + double ans = Math.cos(x); + return ans; + } + public double tangent(double x){ + double ans = Math.tan(x); + return ans; + } + public double inverseSine(double x){ + double ans = Math.asin(x); + return ans; + } + public double inverseCosine(double x){ + double ans = Math.acos(x); + return ans; + } + public double inverseTangent(double x){ + double ans = Math.atan(x); + return ans; + } + public double toRadians(double x){ + double ans = Math.toRadians(x); + return ans; + } + public double toDegrees(double x){ + double ans = Math.toDegrees(x); + return ans; + } + public double factorial(double x){ + double ans = 1; + for(int i=1;i<=x;i++){ + ans *= i; + } + return ans; + } + public double log(double x){ + double ans = Math.log10(x); + return ans; + } + public double inverseLog(double x){ + double ans = Math.pow(10,x); + return ans; + } + public double naturalLog(double x){ + double ans = Math.log(x); + return ans; + } + public double inverseNaturalLog(double x){ + double ans = Math.exp(x); + return ans; + } + private String err(){ + return "Err"; + } + public double convertFtoC(double x) { + double fToC = (x - 32) / 1.8; + return fToC; + } + public double convertCtoF(double x) { + double cToF = (x * 1.8) + 32; + return cToF; + } + public double calcMemory(double x) { + double memory = x; + return memory; + } + //conversions + public String decimalToBinary(double x){ + int conversionInt = (int)x; + String ans = Integer.toString(conversionInt,2); + return ans; + } + public String decimalToHex(double x){ + int conversionInt = (int)x; + String ans = Integer.toString(conversionInt,16); + return ans; + } + public double decimalToOct(double x){ + String octStr = Integer.toOctalString((int) x); + double octNum = Integer.parseInt(octStr); + return octNum; + } + public double octalToHex (double x) { + String stringOct = String.valueOf(x); + double decNum = Integer.parseInt(stringOct, 8); + String hexStr = Integer.toHexString((int)decNum); + double hexNum = Integer.parseInt(hexStr); + return hexNum; + } + public double octalToBinary (double x) { + String stringOct = String.valueOf(x); + double decNum = Integer.parseInt(stringOct, 8); + String binStr = Integer.toHexString((int)decNum); + double binNum = Integer.parseInt(binStr); + return binNum; + } + public double octalToDecimal (double x) { + String stringOct = String.valueOf(x); + double decNum = Integer.parseInt(stringOct, 8); + return decNum; + } + public double hexToOctal (double x) { + String stringHex = String.valueOf(x); + double hexNum = Integer.parseInt(stringHex, 16); + String octStr = Integer.toOctalString((int)hexNum); + double octNum = Integer.parseInt(octStr); + return octNum; + } + public double hexToBinary (double x) { + String stringHex = String.valueOf(x); + double hexNum = Integer.parseInt(stringHex, 16); + String binStr = Integer.toBinaryString((int)hexNum); + double binNum = Integer.parseInt(binStr); + return binNum; + } + public double hexToDecimal (double x) { + String stringHex = String.valueOf(x); + double decNum = Integer.parseInt(stringHex, 8); + return decNum; + } + public double binToDec (double x) { + String stringBin = String.valueOf(x); + double decNum = Integer.parseInt(stringBin, 2); + return decNum; + } + public double binaryToOct (double x) { + String stringBin = String.valueOf(x); + double binNum = Integer.parseInt(stringBin, 2); + String octStr = Integer.toBinaryString((int)binNum); + double octNum = Integer.parseInt(octStr); + return octNum; + } + public double binaryToHex (double x) { + String stringBin = String.valueOf(x); + double binNum = Integer.parseInt(stringBin, 2); + String hexStr = Integer.toBinaryString((int)binNum); + double hexNum = Integer.parseInt(hexStr); + return hexNum; + } + public double convertLBtoKG(double x) { + double lbToKg = (x * 0.45359237); + return lbToKg; + } + public double convertKGtoLB(double x){ + double kgToLb = (x * 2.20462262); + return kgToLb ; + } + public double memAdd(double x){ + memory = x; + return memory; + } + public double memClear(){ + memory = 0; + return memory; + } + public double memRecall(){ + return memory; + } +} \ 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 83f0e97f..548dc1af 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 = 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..9a004386 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -1,17 +1,149 @@ package com.zipcodewilmington.scientificcalculator; - +import java.util.InputMismatchException; /** * Created by leon on 2/9/18. */ public class MainApplication { public static void main(String[] args) { + double currentlyDisplayed = 0; + boolean isRunning = true; + Calculator myCalc = new Calculator(); + myCalc.drawScreen(Double.toString(currentlyDisplayed)); Console.println("Welcome to my calculator!"); - String s = Console.getStringInput("Enter a string"); - Integer i = Console.getIntegerInput("Enter an integer"); - Double d = Console.getDoubleInput("Enter a double."); - - Console.println("The user input %s as a string", s); - Console.println("The user input %s as a integer", i); - Console.println("The user input %s as a d", d); + while(true) { + try { + currentlyDisplayed = Console.getDoubleInput("Please enter your first number:"); + break; + } catch (InputMismatchException e) { + Console.println(""); + } + } + myCalc.drawScreen(Double.toString(currentlyDisplayed)); + while(isRunning) { + String op = Console.getStringInput("Please enter the operation you would like to perform:"); + //prompt user for second number if they choose two variable operator then run two variable operator + if (op.equalsIgnoreCase("add") || op.equalsIgnoreCase("subtract") || op.equalsIgnoreCase("multiply") || op.equalsIgnoreCase("exponential")) { + while(true){ + try{ + double secondNum = Console.getDoubleInput("Please enter your second number:"); + currentlyDisplayed = myCalc.performOperation(op,currentlyDisplayed, secondNum); + myCalc.drawScreen(Double.toString(currentlyDisplayed)); + break; + } + catch(InputMismatchException e) { + Console.println(""); + } + } + } + //handle division by zero + else if (op.equalsIgnoreCase("divide")){ + while(true){ + try{ + double secondNum = Console.getDoubleInput("Please enter your second number:"); + if (secondNum == 0) { + String error = "Can't divide by zero"; + myCalc.drawScreen(error); + } + else { + currentlyDisplayed = myCalc.performOperation(op, currentlyDisplayed, secondNum); + myCalc.drawScreen(Double.toString(currentlyDisplayed)); + } + break; + } + catch(InputMismatchException e) { + Console.println(""); + } + } + } + //run one variable operator + else if (op.equalsIgnoreCase("square") || op.equalsIgnoreCase("square root") || op.equalsIgnoreCase("inverse") || op.equalsIgnoreCase("log")|| op.equalsIgnoreCase("log-1")|| op.equalsIgnoreCase("ln")|| op.equalsIgnoreCase("ln-1")|| op.equalsIgnoreCase("sine")|| op.equalsIgnoreCase("cosine")|| op.equalsIgnoreCase("tangent")|| op.equalsIgnoreCase("factorial")|| op.equalsIgnoreCase("sine-1")|| op.equalsIgnoreCase("cosine-1")|| op.equalsIgnoreCase("tangent-1")|| op.equalsIgnoreCase("invert")|| op.equalsIgnoreCase("ctof")|| op.equalsIgnoreCase("ftoc")|| op.equalsIgnoreCase("lbtokg")|| op.equalsIgnoreCase("kgtolb")|| op.equalsIgnoreCase("radtodeg")|| op.equalsIgnoreCase("degtorad")){ + currentlyDisplayed = myCalc.performOperation(op, currentlyDisplayed); + myCalc.drawScreen(Double.toString(currentlyDisplayed)); + } + //memory add + else if(op.equalsIgnoreCase("m+")){ + myCalc.memAdd(currentlyDisplayed); + String message = currentlyDisplayed + " added to memory"; + myCalc.drawScreen(message); + } + //memory clear + else if(op.equalsIgnoreCase("mc")){ + myCalc.memClear(); + String message = "Memory reset to 0"; + myCalc.drawScreen(message); + } + //memory recall + else if(op.equalsIgnoreCase("mrc")){ + currentlyDisplayed = myCalc.memRecall(); + myCalc.drawScreen(Double.toString(currentlyDisplayed)); + //conversions + } else if (op.equalsIgnoreCase("dectobinary")) { + String stringBinary = myCalc.decimalToBinary(currentlyDisplayed); + currentlyDisplayed = Double.parseDouble(stringBinary); + myCalc.drawScreen(stringBinary); + } else if (op.equalsIgnoreCase("dectohex")) { + String stringBinary = myCalc.decimalToHex(currentlyDisplayed); + currentlyDisplayed = Double.parseDouble(stringBinary); + myCalc.drawScreen(stringBinary); + } else if (op.equalsIgnoreCase("dectooct")) { + double stringBinary = myCalc.decimalToOct(currentlyDisplayed); + String strDecToOct = String.valueOf(stringBinary); + myCalc.drawScreen(strDecToOct); + } else if (op.equalsIgnoreCase("octtohex")) { + double stringOctToHex = myCalc.octalToHex(currentlyDisplayed); + String stringToHex = String.valueOf(stringOctToHex); + myCalc.drawScreen(stringToHex); + } else if (op.equalsIgnoreCase("octtobinary")) { + double numOctToBinary = myCalc.octalToBinary(currentlyDisplayed); + String stringToBinary = String.valueOf(numOctToBinary); + myCalc.drawScreen(stringToBinary); + } else if (op.equalsIgnoreCase("octtodec")) { + double octToDec = myCalc.octalToDecimal(currentlyDisplayed); + String stringToDecimal = String.valueOf(octToDec); + myCalc.drawScreen((stringToDecimal)); + } else if (op.equalsIgnoreCase("hexToBinary")) { + double hexToBin = myCalc.hexToBinary(currentlyDisplayed); + String stringToBinary = String.valueOf(hexToBin); + myCalc.drawScreen(stringToBinary); + } else if (op.equalsIgnoreCase("hextodec")) { + double hexToDec = myCalc.hexToDecimal(currentlyDisplayed); + String stringToDecimal = String.valueOf(hexToDec); + myCalc.drawScreen(stringToDecimal); + }else if (op.equalsIgnoreCase("hextooct")) { + double hexToOct = myCalc.hexToOctal(currentlyDisplayed); + String stringToOct = String.valueOf(hexToOct); + myCalc.drawScreen(stringToOct); + } else if (op.equalsIgnoreCase("binaryToDec")) { + double binToDec = myCalc.binToDec(currentlyDisplayed); + String stringToDec = String.valueOf(binToDec); + myCalc.drawScreen(stringToDec); + } else if (op.equalsIgnoreCase("binaryToOct")) { + double bitToOct = myCalc.binaryToOct(currentlyDisplayed); + String stringToOct = String.valueOf(bitToOct); + myCalc.drawScreen(stringToOct); + } else if (op.equalsIgnoreCase("binaryToHex")) { + double bitToHex = myCalc.binaryToHex(currentlyDisplayed); + String stringToHex = String.valueOf(bitToHex); + myCalc.drawScreen(stringToHex); + //Clear screen + }else if (op.equalsIgnoreCase("clear")) { + currentlyDisplayed = 0; + myCalc.drawScreen(Double.toString(currentlyDisplayed)); + } + else if(op.equalsIgnoreCase("set")){ + double setNum = Console.getDoubleInput("Please enter your number to set:"); + currentlyDisplayed = setNum; + myCalc.drawScreen(Double.toString(currentlyDisplayed)); + } + //quit calc + else if(op.equalsIgnoreCase("quit")){ + isRunning = false; + } + //handle misspelled operator + else{ + String error = "Invalid operator"; + myCalc.drawScreen(error); + } + } } -} +} \ No newline at end of file diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java index 94e8d987..18bce270 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java @@ -1,7 +1,278 @@ package com.zipcodewilmington.scientific_calculator; - +import com.zipcodewilmington.scientificcalculator.Calculator; +import static org.junit.Assert.*; /** * Created by leon on 2/9/18. */ public class TestMainApplication { -} + @org.junit.Before + public void setUp() throws Exception { + } + @org.junit.After + public void tearDown() throws Exception { + } + @org.junit.Test + public void testAddition() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(4.0), myCalc.addition(2,2), 0.00001); + assertEquals(Double.valueOf(100.0), myCalc.addition(79,21), 0.00001); + assertEquals(Double.valueOf(4.0), myCalc.addition(6,-2), 0.00001); + } + @org.junit.Test + public void testSubtraction() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(4.0), myCalc.subtraction(6,2), 0.00001); + assertEquals(Double.valueOf(-20.0), myCalc.subtraction(70,90), 0.00001); + assertEquals(Double.valueOf(4.0), myCalc.subtraction(2,-2), 0.00001); + } + @org.junit.Test + public void testMultiply() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(18.0), myCalc.multiply(6,3), 0.00001); + assertEquals(Double.valueOf(-4.0), myCalc.multiply(-2,2), 0.00001); + assertEquals(Double.valueOf(144.0), myCalc.multiply(12,12), 0.00001); + } + @org.junit.Test + public void testDivide() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(1.0), myCalc.divide(2,2), 0.00001); + assertEquals(Double.valueOf(2.0), myCalc.divide(8,4), 0.00001); + assertEquals(Double.valueOf(0.25), myCalc.divide(1,4), 0.00001); + } + @org.junit.Test + public void testExponential() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(9.0), myCalc.exponential(3,2), 0.00001); + assertEquals(Double.valueOf(8.0), myCalc.exponential(2,3), 0.00001); + assertEquals(Double.valueOf(1.0), myCalc.exponential(2,0), 0.00001); + } + @org.junit.Test + public void testSquare() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(4.0), myCalc.square(2), 0.00001); + assertEquals(Double.valueOf(1.0), myCalc.square(1), 0.00001); + assertEquals(Double.valueOf(1600.0), myCalc.square(40), 0.00001); + } + @org.junit.Test + public void testSquareRoot() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(1.41421), myCalc.squareRoot(2), 0.00001); + assertEquals(Double.valueOf(2.0), myCalc.squareRoot(4), 0.00001); + assertEquals(Double.valueOf(4.0), myCalc.squareRoot(16), 0.00001); + } + @org.junit.Test + public void testInverse() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(0.5), myCalc.inverse(2), 0.00001); + assertEquals(Double.valueOf(2.0), myCalc.inverse(0.5), 0.00001); + assertEquals(Double.valueOf(0.1), myCalc.inverse(10), 0.00001); + } + @org.junit.Test + public void testInvert() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(-2.0), myCalc.invert(2), 0.00001); + assertEquals(Double.valueOf(3.0), myCalc.invert(-3), 0.00001); + assertEquals(Double.valueOf(0.0), myCalc.invert(0), 0.00001); + } + @org.junit.Test + public void testSine() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(0), myCalc.sine(0), 0.00001); + assertEquals(Double.valueOf(0.84147), myCalc.sine(1), 0.00001); + assertEquals(Double.valueOf(0.9093), myCalc.sine(2), 0.00001); + } + @org.junit.Test + public void testCosine() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(1.0), myCalc.cosine(0), 0.00001); + assertEquals(Double.valueOf(0.5403), myCalc.cosine(1), 0.00001); + assertEquals(Double.valueOf(-0.41615), myCalc.cosine(2), 0.00001); + } + @org.junit.Test + public void testTangent() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(0.0), myCalc.tangent(0), 0.00001); + assertEquals(Double.valueOf(1.55741), myCalc.tangent(1), 0.00001); + assertEquals(Double.valueOf(-2.18504), myCalc.tangent(2), 0.00001); + } + @org.junit.Test + public void testInverseSine() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(-1.5708), myCalc.inverseSine(-1), 0.00001); + assertEquals(Double.valueOf(0.0), myCalc.inverseSine(0), 0.00001); + assertEquals(Double.valueOf(1.5708), myCalc.inverseSine(1), 0.00001); + } + @org.junit.Test + public void testInverseCosine() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(3.14159), myCalc.inverseCosine(-1), 0.00001); + assertEquals(Double.valueOf(1.5708), myCalc.inverseCosine(0), 0.00001); + assertEquals(Double.valueOf(0.0), myCalc.inverseCosine(1), 0.00001); + }@org.junit.Test + public void testInverseTangent() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(-0.7854), myCalc.inverseTangent(-1), 0.00001); + assertEquals(Double.valueOf(0.0), myCalc.inverseTangent(0), 0.00001); + assertEquals(Double.valueOf(0.7854), myCalc.inverseTangent(1), 0.00001); + } + @org.junit.Test + public void testFactorial() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(2.0), myCalc.factorial(2), 0.00001); + assertEquals(Double.valueOf(6.0), myCalc.factorial(3), 0.00001); + assertEquals(Double.valueOf(362880.0), myCalc.factorial(9), 0.00001); + } + @org.junit.Test + public void testLog() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(0.0), myCalc.log(1), 0.00001); + assertEquals(Double.valueOf(0.30103), myCalc.log(2), 0.00001); + assertEquals(Double.valueOf(1.0), myCalc.log(10), 0.00001); + } + @org.junit.Test + public void testInverseLog() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(1.0), myCalc.inverseLog(0), 0.00001); + assertEquals(Double.valueOf(2.0), myCalc.inverseLog(0.30103), 0.00001); + assertEquals(Double.valueOf(10.0), myCalc.inverseLog(1), 0.00001); + } + @org.junit.Test + public void testNaturalLog() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(0.0), myCalc.naturalLog(1), 0.00001); + assertEquals(Double.valueOf(2.30259), myCalc.naturalLog(10), 0.00001); + assertEquals(Double.valueOf(0.69315), myCalc.naturalLog(2), 0.00001); + } + @org.junit.Test + public void testInverseNaturalLog() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(1.0), myCalc.inverseNaturalLog(0), 0.0001); + assertEquals(Double.valueOf(10.0), myCalc.inverseNaturalLog(2.30259), 0.0001); + assertEquals(Double.valueOf(2.0), myCalc.inverseNaturalLog(0.69315), 0.0001); + } @org.junit.Test + public void testConvertFtoC() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(32.22222), myCalc.convertFtoC(90), 0.0001); + assertEquals(Double.valueOf(5), myCalc.convertFtoC(41), 0.0001); + assertEquals(Double.valueOf(-17.77778), myCalc.convertFtoC(0), 0.0001); + } + @org.junit.Test + public void testConvertCtoF() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(90), myCalc.convertCtoF(32.22222), 0.0001); + assertEquals(Double.valueOf(41), myCalc.convertCtoF(5), 0.0001); + assertEquals(Double.valueOf(0), myCalc.convertCtoF(-17.77778), 0.0001); + } + @org.junit.Test + public void testConvertLBtoKG() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(0.45359), myCalc.convertLBtoKG(1), 0.0001); + assertEquals(Double.valueOf(10.43262), myCalc.convertLBtoKG(23), 0.0001); + assertEquals(Double.valueOf(206.8381), myCalc.convertLBtoKG(456), 0.0001); + } + @org.junit.Test + public void testConvertKGtoLB() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(1), myCalc.convertKGtoLB(0.45359), 0.0001); + assertEquals(Double.valueOf(23), myCalc.convertKGtoLB(10.43262), 0.0001); + assertEquals(Double.valueOf(456), myCalc.convertKGtoLB(206.8381), 0.0001); + } + @org.junit.Test + public void testToRadians() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(0), myCalc.toRadians(0), 0.0001); + assertEquals(Double.valueOf(1.5708), myCalc.toRadians(90), 0.0001); + assertEquals(Double.valueOf(3.14159), myCalc.toRadians(180), 0.0001); + } + @org.junit.Test + public void testToDegrees() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(0), myCalc.toDegrees(0), 0.001); + assertEquals(Double.valueOf(90), myCalc.toDegrees(1.5708), 0.001); + assertEquals(Double.valueOf(180), myCalc.toDegrees(3.14159), 0.001); + } + /*@org.junit.Test + public void testDecToBinary() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(10), myCalc.decimalToBinary(2)); + assertEquals(Double.valueOf(1), myCalc.decimalToBinary(1)); + assertEquals(Double.valueOf(1000), myCalc.decimalToBinary(8)); + } + @org.junit.Test + public void testDecToOct() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(2), myCalc.decimalToOct(2)); + assertEquals(Double.valueOf(10), myCalc.decimalToOct(8)); + assertEquals(Double.valueOf(170), myCalc.decimalToOct(120)); + } + @org.junit.Test + public void testDecToHex() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(2), myCalc.decimalToHex(2)); + assertEquals(Double.valueOf(14), myCalc.decimalToHex(20)); + assertEquals("1f", myCalc.decimalToHex(31)); + } + @org.junit.Test + public void testBinaryToDec() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(2), myCalc.binToDec(10)); + assertEquals(Double.valueOf(1), myCalc.binToDec(1)); + assertEquals(Double.valueOf(8), myCalc.binToDec(1000)); + } + @org.junit.Test + public void testBinaryToOct() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(2), myCalc.binaryToOct(10)); + assertEquals(Double.valueOf(17), myCalc.binaryToOct(1111)); + assertEquals(Double.valueOf(10), myCalc.binaryToOct(1000)); + } + @org.junit.Test + public void testBinaryToHex() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(2), myCalc.binaryToHex(10)); + assertEquals(Double.valueOf(10), myCalc.binaryToHex(10000)); + assertEquals("1f", myCalc.binaryToHex(11111)); + } + @org.junit.Test + public void testOctToBinary() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(10), myCalc.octalToBinary(2)); + assertEquals(Double.valueOf(1), myCalc.octalToBinary(1)); + assertEquals(Double.valueOf(1000), myCalc.octalToBinary(10)); + } + @org.junit.Test + public void testOctToDec() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(2), myCalc.octalToDecimal(2)); + assertEquals(Double.valueOf(8), myCalc.octalToDecimal(10)); + assertEquals(Double.valueOf(120), myCalc.octalToDecimal(170)); + } + @org.junit.Test + public void testOctToHex() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(2), myCalc.octalToHex(2)); + assertEquals("e", myCalc.octalToHex(16)); + assertEquals(Double.valueOf(19), myCalc.octalToHex(31)); + } + @org.junit.Test + public void testHexToBinary() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(2), myCalc.hexToBinary(2)); + assertEquals(Double.valueOf(15), myCalc.hexToBinary("f")); + assertEquals(Double.valueOf(171), myCalc.hexToBinary("ab")); + } + @org.junit.Test + public void testHexToOct() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(2), myCalc.hexToOctal(2)); + assertEquals(Double.valueOf(17), myCalc.hexToOctal("f")); + assertEquals(Double.valueOf(252), myCalc.hexToOctal("ab")); + } + @org.junit.Test + public void testHexToDec() { + Calculator myCalc = new Calculator(); + assertEquals(Double.valueOf(10), myCalc.hexToDecimal(2)); + assertEquals(Double.valueOf(1111), myCalc.hexToDecimal("f")); + assertEquals(Double.valueOf(10101011), myCalc.hexToDecimal("ab")); + }*/ +} \ No newline at end of file diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplicationTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplicationTest.java new file mode 100644 index 00000000..05f7dfd4 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplicationTest.java @@ -0,0 +1,14 @@ +package com.zipcodewilmington.scientific_calculator; + +import static org.junit.jupiter.api.Assertions.*; + +class TestMainApplicationTest { + + @org.junit.jupiter.api.BeforeEach + void setUp() { + } + + @org.junit.jupiter.api.AfterEach + void tearDown() { + } +} \ No newline at end of file diff --git a/src/uml.puml b/src/uml.puml new file mode 100644 index 00000000..4b24fc52 --- /dev/null +++ b/src/uml.puml @@ -0,0 +1,91 @@ +@startuml +<<<<<<< HEAD + +class MainApplication{ + double currentlyDisplayed + double memory + boolean isRunning +} + +class Console{ + getStringInput() + getDoubleInput() +} + +class Calculator{ + drawScreen() + performOperation(String, double, double) + performOperation(String, double) + addition() + subtraction() + multiply() + divide() + exponential() + square() + squareRoot() + inverse() + invert() + sine() + cosine() + tangent() + inverseSine() + inverseCosine() + inverseTangent() + factorial() + log() + inverseLog() + naturalLog() + inverseNaturalLog() + convertFtoC() + convertCtoF() + convertLBtoKG() + convertKGtoLB() + toRadians() + toDegrees() + decToBinary() + decToOct() + decToHex() + binaryToDec() + binaryToOct() + binaryToHex() + octToBinary() + octToDec() + octToHex() + hexToBinary() + hexToOct() + hexToDec() +} + +MainApplication <|-- Console +MainApplication <|-- Calculator + + + +======= +'https://plantuml.com/class-diagram + +abstract class AbstractList +abstract AbstractCollection +interface List +interface Collection + +List <|-- AbstractList +Collection <|-- AbstractCollection + +Collection <|- List +AbstractCollection <|- AbstractList +AbstractList <|-- ArrayList + +class ArrayList { +Object[] elementData +size() +} + +enum TimeUnit { +DAYS +HOURS +MINUTES +} +>>>>>>> 2269485a535b70f06303894d97a1ad9bd96fbc89 + +@enduml \ No newline at end of file