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/BasicCalculator.java b/src/main/java/com/zipcodewilmington/scientificcalculator/BasicCalculator.java
new file mode 100644
index 00000000..ee95bbac
--- /dev/null
+++ b/src/main/java/com/zipcodewilmington/scientificcalculator/BasicCalculator.java
@@ -0,0 +1,118 @@
+package com.zipcodewilmington.scientificcalculator;
+
+import java.util.Scanner;
+
+public class BasicCalculator {
+ private Double state = 0.0;
+ static private Scanner prompt = new Scanner(System.in);
+
+ public void promptScreen() {
+ System.out.println("Result: " + state.toString() + "\n\n");
+
+ System.out.println("Choose your basic function");//
+ System.out.println("1. ADD, 2. SUBTRACT, 3. DIVIDE, 4. MULTIPLY 5. SQUARE");
+ System.out.println("6. SQUAREROOT, 7. EXPONENTIAL, 8. INVERSE, 9. SWITCHTHESIGN, 10. AVERAGE 11. COUNTDOWN");
+
+
+ String functionPrompt = prompt.nextLine();
+ while (functionPrompt.length() == 0) {
+ functionPrompt = prompt.nextLine();
+ }
+ int function = Integer.valueOf(functionPrompt);
+
+ if (function == 1) {
+ System.out.print( " Second number is : ");
+ Double num2 = prompt.nextDouble();
+ state = addition(state, num2);
+ } else if (function == 2) {
+ System.out.print( " Second number is : ");
+ Double num2 = prompt.nextDouble();
+ state = subtraction(state, num2);
+ } else if (function == 3) {
+ System.out.print( " Second number is : ");
+ Double num2 = prompt.nextDouble();
+ state = division(state, num2);
+ } else if (function == 4) {
+ System.out.print( " Second number is : ");
+ Double num2 = prompt.nextDouble();
+ state = multiply(state, num2);
+ } else if (function == 5) {
+ state = square(state);
+ } else if (function == 6) {
+ state = squareRoot(state);
+ } else if (function == 7) {
+ System.out.print( " Second number is : ");
+ Double num2 = prompt.nextDouble();
+ state = exponential(state, num2);
+ } else if (function == 8) {
+ state = inverse(state);
+ } else if (function == 9) {
+ state = switchTheSign(state);
+ } else if (function == 10){
+ System.out.print( " Second number is : ");
+ Double num2 = prompt.nextDouble();
+ state = average(state, num2);
+ } else if (function == 11){
+ state = countdown(state);
+ }
+ // return Calculator();
+
+ }
+
+ public Double addition(Double num1, Double num2) {
+ return num1 + num2;
+ }
+
+ public double add ( double num1, double num2) {
+ return num1 + num2 ;
+ }
+
+
+ public double subtraction ( double num1, double num2) {
+ return num1 - num2;
+ }
+
+ public double subst ( double num1, double num2) {
+ return num1 - num2 ;
+ }
+
+ public double division ( double num1, double num2) {return num1 / num2 ;}
+
+ public double div ( double num1, double num2) {
+ return num1/num2 ;
+ }
+
+ public double multiply ( double num1, double num2) {return num1 * num2 ;}
+
+ public double multi ( 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 sqroot ( double num1) {return Math.sqrt(num1) ;}
+
+ public double exponential ( double num1, double num2) { return Math.pow( num1, num2) ;}
+
+ public double exponent ( double num1, double num2) { return Math.pow( num1, num2) ;}
+
+ public double inverse (double num2) {return (1/num2) ;}
+
+ public double inv (double num2) {return (1/num2) ;}
+
+ public double switchTheSign ( double num1) { return num1 * -1;}
+
+ public double SignNumb (double num1) { return num1 * -1;}
+
+ public double average ( double num1, double num2) { return (num1/num2)/ (2);}
+
+ public double avg (double num1, double num2, double value1) { return (num1/num2)/ (2);}
+
+ public double countdown ( double num1) {return num1 - 1;}
+
+ public double countDown (double num1) {return num1 - 1;}
+
+ }
+
+
+
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..d644fa34
--- /dev/null
+++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java
@@ -0,0 +1,74 @@
+package com.zipcodewilmington.scientificcalculator;
+
+import sun.lwawt.macosx.CPrinterDevice;
+
+import java.security.Principal;
+
+public class Calculator {
+ String output;
+ String calcState;
+ Integer retries;
+ scientificCalc sc;
+ BasicCalculator bc;
+
+ public Calculator(String op, scientificCalc scienCalc, BasicCalculator basicCalc) {
+ output = op;
+ calcState = null;
+ retries = 0;
+ sc = scienCalc;
+ bc = basicCalc;
+
+ }
+
+ public void startCalc(Integer retries) {
+ Console.println("Please enter 1 for a Basic Calculator or 2 for a Scientific Calculator.");
+ String i = Console.getStringInput("Enter an integer!");
+ if (i.equals("1")) {
+ Console.println("This calculator does the following:");
+ Console.println("add, subtract, multiply, divide, calculate the square,");
+ Console.println("take the square root, variable exponentiation,");
+ Console.println("take the inverse, switch signs, average, and counting down/up.");
+ setCalcState(i);
+ } else if (i.equals("2")) {
+ Console.println("This calculator does the following:");
+ Console.println("switch displays, commit to memory, clear memory, ine, cosine,");
+ Console.println("tangent, inverse sine, inverse cosine, inverse tangent, switch units,");
+ Console.println("log, inverse log, natural log, inverse of natural log, and factorials.");
+ setCalcState(i);
+ } else if (retries < 5) {
+ Console.println("User input %s is invalid.", i);
+ retries += 1;
+ startCalc(retries);
+ } else {
+ Console.println("User input %s is invalid.", i);
+ Console.println("User has surpassed max number of retries.");
+ }
+ }
+
+ /* public void displayOutput(String outResult) {
+ output = outResult;
+ //Console.println(outResult);
+ } */
+
+ public void setCalcState(String inputReceived){
+ calcState = inputReceived;
+ if (inputReceived == null ? "2" == null : inputReceived.equals("2"))
+ sc.promptScreen();
+ else {
+ bc.promptScreen();
+ }
+
+ }
+
+ public void clear() {
+ String clearer = "";
+ for (int i = 0; i < 70; i++) {
+ clearer += "\n";
+ }
+ System.out.println(clearer);
+
+ }
+
+
+}
+
diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java
index 83f0e97f..d41781b7 100644
--- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java
+++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java
@@ -23,10 +23,12 @@ public static String getStringInput(String prompt) {
}
public static Integer getIntegerInput(String prompt) {
+
return null;
}
public static Double getDoubleInput(String prompt) {
+
return null;
}
}
diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java
index 5f421325..f628d686 100644
--- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java
+++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java
@@ -4,14 +4,23 @@
* Created by leon on 2/9/18.
*/
public class MainApplication {
+
+
public static void main(String[] args) {
+ scientificCalc sc = new scientificCalc();
+ BasicCalculator bc = new BasicCalculator();
+ //basicCalculator bc = new basicCalculator(); needs Tra's code, make sure to add params if he has them
+ Calculator calc = new Calculator("0", sc, bc);
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.");
+ calc.startCalc(0);
+
+ //calc.displayOutput("2");
- 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);
+// BasicCalculator basicCalcObject = new BasicCalculator();
+// while (true) {
+// basicCalcObject.promptScreen();
+// }
+// scientificCalc scientificCalcObject = new scientificCalc();
+// scientificCalcObject.promptScreen();
}
}
diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/scientificCalc.java b/src/main/java/com/zipcodewilmington/scientificcalculator/scientificCalc.java
new file mode 100644
index 00000000..6432dd3c
--- /dev/null
+++ b/src/main/java/com/zipcodewilmington/scientificcalculator/scientificCalc.java
@@ -0,0 +1,132 @@
+package com.zipcodewilmington.scientificcalculator;
+
+import java.util.Scanner;
+
+public class scientificCalc {
+ static Scanner prompt = new Scanner(System.in);
+
+ public double promptScreen() {
+ System.out.println("Choose your scientific function");//
+ System.out.println("1. SIN, 2. SIN-1, 3. COS, 4. COS-1 5. TAN");
+ System.out.println("6. TAN-1, 7. LOG, 8. LOG10, 9. LOG1P, 10. FAC");
+
+ int function = Integer.valueOf(prompt.nextLine());
+
+ if (function == 1) {
+ return sine();
+ } else if (function == 2) {
+ return inverseSine();
+ } else if (function == 3) {
+ return cosign();
+ } else if (function == 4) {
+ return inverseCoSine();
+ } else if (function == 5) {
+ return tangent();
+ } else if (function == 6) {
+ return inverseTangent();
+ } else if (function == 7) {
+ return logarithm();
+ } else if (function == 8) {
+ return logarithm10();
+ } else if (function == 9) {
+ return logp();
+ } else if (function == 10){
+ return factorial();
+ }
+ return promptScreen();
+ }
+
+ public double sine() { // 1
+ System.out.println("Give number:");
+ double first = Integer.valueOf(prompt.nextLine());
+ double result = sineOf(first);
+ System.out.println(result);
+ return result;
+ }
+
+ public double sineOf(double num1) {
+ return Math.sin(num1);
+ }
+
+ public double inverseSine() { // 2
+ System.out.println("Give number:");
+ double first = Integer.valueOf(prompt.nextLine());
+ System.out.println(Math.asin(first));
+ return (int) Math.asin(first);
+ }
+ public double inversesineOf(double num1) {
+ return Math.asin(num1);
+ }
+
+ public double cosign() { // 3
+ System.out.println("Give number:");
+ double first = Integer.valueOf(prompt.nextLine());
+ System.out.println(Math.cos(first));
+ return Math.cos(first);
+ }
+
+ public double inverseCoSine() { // 4
+ System.out.println("Give number:");
+ double first = Integer.valueOf(prompt.nextLine());
+ System.out.println(Math.acos(first));
+ return (int) Math.acos(first);
+ }
+
+ public double tangent() { // 5
+ System.out.println("Give number:");
+ double first = Integer.valueOf(prompt.nextLine());
+ System.out.println(Math.tan(first));
+ return Math.tan(first);
+ }
+
+ public double inverseTangent() { // 6
+ System.out.println("Give number:");
+ double first = Integer.valueOf(prompt.nextLine());
+ System.out.println(Math.atan(first));
+ return Math.atan(first);
+ }
+
+ public double logarithm() { // 7
+ System.out.println("Give number:");
+ int first = Integer.valueOf(prompt.nextLine());
+ System.out.println(Math.log(first));
+ return Math.log(first);
+ }
+
+ public double logarithm10() { // 8
+ System.out.println("Give number:");
+ int first = Integer.valueOf(prompt.nextLine());
+ System.out.println(Math.log10(first));
+ return Math.log10(first);
+ }
+
+ public double logp() { // 9
+ System.out.println("Give number:");
+ double first = Integer.valueOf(prompt.nextLine());
+
+ return Math.pow(Math.E, (Math.log(first)));
+ //System.out.println(Math.E,(Math.log(first)));
+ }
+ public long factorial() { // 10
+ System.out.println("Give number:");
+ long first = Integer.valueOf(prompt.nextLine());
+ long fact = 1;
+ for (int i = 2; i <= first; i++) {
+ fact = fact * i;
+ }
+ System.out.println(fact);
+ return (fact);
+ }
+}
+
+//New Comment.
+
+
+
+
+
+
+
+
+
+
diff --git a/src/test/java/com/zipcodewilmington/scientificcalculator/BasicCalculatorTest.java b/src/test/java/com/zipcodewilmington/scientificcalculator/BasicCalculatorTest.java
new file mode 100644
index 00000000..4ba0c8e4
--- /dev/null
+++ b/src/test/java/com/zipcodewilmington/scientificcalculator/BasicCalculatorTest.java
@@ -0,0 +1,22 @@
+package com.zipcodewilmington.scientificcalculator;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class BasicCalculatorTest {
+
+ @Test
+ public void addTest() {
+ BasicCalculator adding = new BasicCalculator();
+ double actual = adding.add(10, 5);
+ double expected = 15;
+ Assert.assertEquals(expected, actual, 0);
+ }
+ @Test
+ public void subTest() {
+ BasicCalculator subtracting = new BasicCalculator();
+ double actual = subtracting.subst(10, 5);
+ double expected = 5;
+ Assert.assertEquals(expected, actual, 0);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/com/zipcodewilmington/scientificcalculator/scientificCalcTest.java b/src/test/java/com/zipcodewilmington/scientificcalculator/scientificCalcTest.java
new file mode 100644
index 00000000..d274a333
--- /dev/null
+++ b/src/test/java/com/zipcodewilmington/scientificcalculator/scientificCalcTest.java
@@ -0,0 +1,59 @@
+package com.zipcodewilmington.scientificcalculator;
+import java.lang.Math;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class scientificCalcTest {
+
+ @Test
+ public void sine() {
+ // given 30
+ double sine = Math.toRadians(30);
+ scientificCalc sineCalc = new scientificCalc();
+ double actual = sineCalc.sineOf(sine);
+ double expected = 0.5;
+ Assert.assertEquals(expected, actual, 0.00001);
+ }
+
+ @Test
+ public void inverseSine() {
+ double inversesine = 0.2;
+ scientificCalc inversesineCalc = new scientificCalc();
+ double actual = inversesineCalc.inversesineOf(inversesine);
+ double expected = 0.201358;
+ Assert.assertEquals(expected, actual, 0.0001);
+ }
+
+ @org.junit.Test
+ public void cosign() {
+ }
+
+ @org.junit.Test
+ public void inverseCoSine() {
+ }
+
+ @org.junit.Test
+ public void tangent() {
+ }
+
+ @org.junit.Test
+ public void inverseTangent() {
+ }
+
+ @org.junit.Test
+ public void logarithm() {
+ }
+
+ @org.junit.Test
+ public void logarithm10() {
+ }
+
+ @org.junit.Test
+ public void logp() {
+ }
+
+ @org.junit.Test
+ public void factorial() {
+ }
+}
\ No newline at end of file