diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 00000000..963faeba
Binary files /dev/null and b/.DS_Store differ
diff --git a/UML.png b/UML.png
new file mode 100644
index 00000000..49cb5e05
Binary files /dev/null and b/UML.png differ
diff --git a/pom.xml b/pom.xml
index e7cb4f6b..8ef0e24d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,6 +7,17 @@
com.zipcodewilmington
scientific_calculator
1.0-SNAPSHOT
-
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+
+ 1.8
+ 1.8
+
\ No newline at end of file
diff --git a/src/main/.idea/misc.xml b/src/main/.idea/misc.xml
new file mode 100644
index 00000000..28a804d8
--- /dev/null
+++ b/src/main/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/.idea/modules.xml b/src/main/.idea/modules.xml
new file mode 100644
index 00000000..aaf7df43
--- /dev/null
+++ b/src/main/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/.idea/vcs.xml b/src/main/.idea/vcs.xml
new file mode 100644
index 00000000..b2bdec2d
--- /dev/null
+++ b/src/main/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/.idea/workspace.xml b/src/main/.idea/workspace.xml
new file mode 100644
index 00000000..9c05f9f2
--- /dev/null
+++ b/src/main/.idea/workspace.xml
@@ -0,0 +1,115 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1571592950549
+
+
+ 1571592950549
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/.idea/misc.xml b/src/main/java/com/.idea/misc.xml
new file mode 100644
index 00000000..28a804d8
--- /dev/null
+++ b/src/main/java/com/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/.idea/modules.xml b/src/main/java/com/.idea/modules.xml
new file mode 100644
index 00000000..a8b7e67f
--- /dev/null
+++ b/src/main/java/com/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/.idea/vcs.xml b/src/main/java/com/.idea/vcs.xml
new file mode 100644
index 00000000..4fce1d86
--- /dev/null
+++ b/src/main/java/com/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/.idea/workspace.xml b/src/main/java/com/.idea/workspace.xml
new file mode 100644
index 00000000..126e7e0e
--- /dev/null
+++ b/src/main/java/com/.idea/workspace.xml
@@ -0,0 +1,117 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1571517158932
+
+
+ 1571517158932
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
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..fb8f1676
--- /dev/null
+++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java
@@ -0,0 +1,235 @@
+package com.zipcodewilmington.scientificcalculator;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Scanner;
+
+
+class Calculator extends MainApplication {
+ private Scanner scanner = new Scanner(System.in);
+
+ //create an array that includes all of the available operators
+ private String[] operators = {"1", "2", "3", "4", "5", "6", "7", "8", "9",
+ "10", "11", "12", "13,", "14", "15", "16",
+ "17", "18", "19", "20", "return"};
+ //turn that array into a string
+ private List operatorsList = Arrays.asList(operators);
+ //create an array of each operation that requires two values
+ private String[] need2Values = {"1", "2", "3", "4", "5"};
+ //turn that array into a string
+ private List need2ValuesList = Arrays.asList(need2Values);
+
+ void runCalculator() {
+ while (true) {
+ //ask the user for a operator
+ System.out.println("Choose your Operator\nType \"cmd\" for commands.");
+ String userOperator = Console.getStringInput(":");
+
+ while (!operatorsList.contains(userOperator)) {
+ //provide a list of commands
+ if (userOperator.equals("cmd")) {
+ System.out.println("\"1\" - + - Addition");
+ System.out.println("\"2\" - - - Subtraction");
+ System.out.println("\"3\" - * - Multiplication");
+ System.out.println("\"4\" - / - Division");
+ System.out.println("\"5\" - x^y - Exponential");
+ System.out.println("\"6\" - x^2 - Squared");
+ System.out.println("\"7\" - √ -Square Root");
+ System.out.println("\"8\" - !x - Factorial");
+ System.out.println("\"9\" - 1/x - Inverse");
+ System.out.println("\"10\" - +- - Invert");
+ System.out.println("\"11\" - sin(x) - Sine");
+ System.out.println("\"12\" - cos(x) - Cosine");
+ System.out.println("\"13\" - tan(x) - Tangent");
+ System.out.println("\"14\" - sin(x)^-1 - Inverse Sine");
+ System.out.println("\"15\" - cos(x)^-1 - Inverse Cosine");
+ System.out.println("\"16\" - tan(x)^-1 - Inverse Tangent");
+ System.out.println("\"17\" - log(x) - Logarithm");
+ System.out.println("\"18\" - 10^x - Inverse Logarithm");
+ System.out.println("\"19\" - ln(x) - Natural Logarithm");
+ System.out.println("\"20\" - e^x - Inverse Natural Logarithm");
+ //give an option to exit the calculator and go back to the main menu
+ System.out.println("****\"return\" - Return to Main Menu");
+ //check if operator is correct, and break the loop
+ } else if (operatorsList.contains(userOperator)) {
+ break;
+ //return an error if operator is not correct, and return to top of loop
+ } else {
+ System.out.println("ERROR: Invalid command\n");
+ }
+ System.out.println("Choose your Operator\nType \"cmd\" for commands.");
+ userOperator = Console.getStringInput(": ");
+ }
+ if(userOperator.equals("return")){
+ break;
+ }
+
+
+ //ask the user for a value
+ System.out.println("Enter your value");
+ String userValue = Console.getStringInput(":");
+ boolean correctInput;
+ //run a while loop that checks if a proper number was entered
+ while(true) {
+ correctInput = InputChecker.isNumeric(userValue);
+ if(correctInput) break;
+ System.out.println("Enter your value");
+ userValue = Console.getStringInput(":");
+ }
+ double userValue1 = Double.parseDouble(userValue);
+ if (need2ValuesList.contains(userOperator)) {
+ //ask for a second value
+ System.out.println("Enter your second value");
+ userValue = Console.getStringInput(":");
+ //run a while loop that checks if a proper number was entered
+ while(true) {
+ correctInput = InputChecker.isNumeric(userValue);
+ if(correctInput) break;
+ System.out.println("Enter your second value");
+ userValue = Console.getStringInput(":");
+ }
+ double userValue2 = Double.parseDouble(userValue);
+
+ //run the need2value operators INSIDE the if statement
+ switch (userOperator) {
+ case "1":
+ Console add = new Console();
+ double sum = add.add(userValue1, userValue2);
+ System.out.println(userValue1 + " + " + userValue2 + " = " + sum + "\n");
+ break;
+ case "2":
+ Console subtract = new Console();
+ Double difference = subtract.subtract(userValue1, userValue2);
+ System.out.println(userValue1 + " - " + userValue2 + " = " + difference + "\n");
+ break;
+ case "3":
+ Console multiply = new Console();
+ Double product = multiply.multiply(userValue1, userValue2);
+ System.out.println(userValue1 + " * " + userValue2 + " = " + product + "\n");
+ break;
+ case "4":
+ Console divide = new Console();
+ Double quotient = divide.divide(userValue1, userValue2);
+ if (quotient != null) {
+ System.out.println(userValue1 + " / " + userValue2 + " = " + quotient + "\n");
+ }
+ break;
+ case "5":
+ Console exponent = new Console();
+ Double powerOf = exponent.exponent(userValue1, userValue2);
+ System.out.println(userValue1 + " ^ " + userValue2 + " = " + powerOf + "\n");
+ break;
+ }
+ } else if (!need2ValuesList.contains(userOperator)) {
+ switch (userOperator) {
+ case "6":
+ Console squared = new Console();
+ Double powerOf = squared.squared(userValue1);
+ System.out.println(userValue1 + " ^2 = " + powerOf + "\n");
+ break;
+ case "7":
+ Console sqrt = new Console();
+ Double squareRoot = sqrt.sqrt(userValue1);
+ if (squareRoot != null)
+ System.out.println("√" + userValue1 + " = " + squareRoot + "\n");
+ break;
+ case "8":
+ Console factorial = new Console();
+ Double facto = factorial.factorial(userValue1);
+ System.out.println("!" + userValue1 + " = " + facto + "\n");
+ break;
+ case "9":
+ Console inverse = new Console();
+ Double inversed = inverse.inverse(userValue1);
+ if (inversed != null)
+ System.out.println("1/" + userValue1 + " = " + inversed + "\n");
+ break;
+ case "10":
+ Console invert = new Console();
+ Double inverted = invert.invert(userValue1);
+ System.out.println(userValue1 + " inverted = " + inverted + "\n");
+ break;
+ case "11":
+ Console sine = new Console();
+ Double sin = sine.sine(userValue1);
+ String trigFunction = Console.degreesRadians();
+ if(trigFunction.equals("Radians"))
+ System.out.println("sin(" + userValue1 + ") = " + Math.toRadians(sin) + "\n");
+ else
+ System.out.println("sin(" + userValue1 + ") = " + Math.toDegrees(sin) + "\n");
+ break;
+ case "12":
+ Console cosine = new Console();
+ Double cos = cosine.cosine(userValue1);
+ trigFunction = Console.degreesRadians();
+ if(trigFunction.equals("Radians"))
+ System.out.println("sin(" + userValue1 + ") = " + Math.toRadians(cos) + "\n");
+ else
+ System.out.println("cos(" + userValue1 + ") = " + Math.toDegrees(cos) + "\n");
+ break;
+ case "13":
+ Console tangent = new Console();
+ Double tan = tangent.tangent(userValue1);
+ trigFunction = Console.degreesRadians();
+ if(trigFunction.equals("Radians"))
+ System.out.println("tan(" + userValue1 + ") = " + Math.toRadians(tan) + "\n");
+ else
+ System.out.println("tan(" + userValue1 + ") = " + Math.toDegrees(tan) + "\n");
+ break;
+ case "14":
+ Console inverseSine = new Console();
+ Double inverseSin = inverseSine.inverseSine(userValue1);
+ trigFunction = Console.degreesRadians();
+ if(trigFunction.equals("Radians"))
+ System.out.println("sin(" + userValue1 + ")^-1 = " + Math.toRadians(inverseSin) + "\n");
+ else
+ System.out.println("sin(" + userValue1 + ")^-1 = " + Math.toDegrees(inverseSin) + "\n");
+ break;
+ case "15":
+ Console inverseCosine = new Console();
+ Double inverseCos = inverseCosine.inverseCosine(userValue1);
+ trigFunction = Console.degreesRadians();
+ if(trigFunction.equals("Radians"))
+ System.out.println("cos(" + userValue1 + ")^-1 = " + Math.toRadians(inverseCos) + "\n");
+ else
+ System.out.println("cos(" + userValue1 + ")^-1 = " + Math.toDegrees(inverseCos) + "\n");
+ break;
+ case "16":
+ Console inverseTangent = new Console();
+ Double inverseTan = inverseTangent.inverseTangent(userValue1);
+ trigFunction = Console.degreesRadians();
+ if(trigFunction.equals("Radians"))
+ System.out.println("tan(" + userValue1 + ")^-1 = " + Math.toRadians(inverseTan) + "\n");
+ else
+ System.out.println("tan(" + userValue1 + ")^-1 = " + Math.toDegrees(inverseTan) + "\n");
+ break;
+ case "17":
+ Console logarithm = new Console();
+ Double log = logarithm.logarithm(userValue1);
+ if (log != null)
+ System.out.println("Log(" + userValue1 + ") = " + log + "\n");
+ break;
+ case "18":
+ Console inverseLogarithm = new Console();
+ Double inverseLog = inverseLogarithm.inverseLogarithm(userValue1);
+ if (inverseLog != null)
+ System.out.println("10^" + userValue1 + " = " + inverseLog + "\n");
+ break;
+ case "19":
+ Console naturalLogarithm = new Console();
+ Double naturalLog = naturalLogarithm.naturalLogarithm(userValue1);
+ if(naturalLog != null)
+ System.out.println("ln(" + userValue1 + ") = " + naturalLog + "\n");
+ break;
+ case "20":
+ Console inverseNaturalLogarithm = new Console();
+ Double inverseNatLog = inverseNaturalLogarithm.inverseNaturalLogarithm(userValue1);
+ System.out.println("e^" + userValue1 + " = " + inverseNatLog + "\n");
+ break;
+ }
+ }
+ }
+ }
+ }
+
+
diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java
index 83f0e97f..b84cb448 100644
--- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java
+++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java
@@ -1,13 +1,17 @@
package com.zipcodewilmington.scientificcalculator;
+import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;
+import org.w3c.dom.ls.LSOutput;
+
+import java.sql.SQLOutput;
import java.util.Scanner;
/**
* Created by leon on 2/9/18.
*/
-public class Console {
+public class Console extends Calculator {
- public static void print(String output, Object... args) {
+ private static void print(String output, Object... args) {
System.out.printf(output, args);
}
@@ -15,18 +19,176 @@ public static void println(String output, Object... args) {
print(output + "\n", args);
}
- public static String getStringInput(String prompt) {
+ static String getStringInput(String prompt) {
Scanner scanner = new Scanner(System.in);
- println(prompt);
- String userInput = scanner.nextLine();
- return userInput;
+ print(prompt);
+ return scanner.nextLine();
+ }
+
+ static Integer getIntegerInput(String prompt) {
+ return getDoubleInput(prompt).intValue();
+ }
+
+ static Double getDoubleInput(String prompt) {
+ return Double.parseDouble(getStringInput(prompt));
+ }
+
+ Double add(double value1, double value2) {
+ return value1 + value2;
+ }
+
+ Double subtract(double value1, double value2) {
+ return value1 - value2;
+ }
+
+ Double multiply(double value1, double value2) {
+ return value1 * value2;
+ }
+
+ Double divide(double value1, double value2) {
+ if (value2 == 0) {
+ System.out.println("ERROR: Cannot divide by 0.");
+ return null;
+ } else {
+ return value1 / value2;
+ }
+ }
+
+ Double exponent(double value1, double value2) {
+ return Math.pow(value1, value2);
+ }
+
+ Double cosine(double value) {
+ if (value < 0) {
+ return Math.cos(-value);
+ } else {
+ return Math.cos(value);
+ }
+ }
+
+ Double factorial(Double value1) {
+ double facto = 1;
+ for (int i = 1; i <= value1; i++) {
+ facto = facto * i;
+ }
+ return facto;
+ }
+
+ Double inverse(Double value) {
+ if (value == 0) {
+ System.out.println("ERROR: Cannot have an inverse of 0.");
+ return null;
+ } else {
+ return 1 / value;
+ }
+ }
+
+ Double inverseCosine(double value) {
+ if (value <= 1 && value >= -1) {
+ return Math.acos(value);
+ } else {
+ System.out.println("ERROR: Please enter a number between -1 and 1.");
+ return null;
+ }
+ }
+
+ Double inverseLogarithm(double value) {
+ if (value <= 0) {
+ System.out.println("ERROR: Please enter a number larger than 0.");
+ return null;
+ } else {
+ return Math.pow(10, value);
+ }
}
- public static Integer getIntegerInput(String prompt) {
- return null;
+ Double inverseNaturalLogarithm(double value) {
+ return Math.exp(value);
}
- public static Double getDoubleInput(String prompt) {
- return null;
+ Double inverseSine(double value) {
+ if (value <= 1 && value >= -1) {
+ return Math.asin(value);
+ } else {
+ System.out.println("ERROR: Please enter a number between -1 and 1.");
+ return null;
+ }
+ }
+
+ Double inverseTangent(double value) {
+ return Math.atan(value);
+ }
+
+ Double invert(double value1) {
+ return value1 * -1;
+ }
+
+ Double logarithm(double value) {
+ if (value <= 0) {
+ System.out.println("ERROR: Please enter a number larger than 0.");
+ return null;
+ } else {
+ return Math.log10(value);
+ }
+ }
+
+ Double sine(double value) {
+ if (value < 0) {
+ return Math.sin(-value);
+ } else {
+ return Math.sin(value);
+ }
+ }
+
+ Double sqrt(double value) {
+ if (value <= 0) {
+ System.out.println("ERROR: Please enter a positive number.");
+ return null;
+ } else {
+ return Math.sqrt(value);
+ }
+ }
+
+ Double squared(double value1) {
+ return value1 * value1;
+ }
+
+ Double tangent(double value) {
+ if (value < 0) {
+ return Math.tan(-value);
+ } else {
+ return Math.tan(value);
+ }
+ }
+
+ Double naturalLogarithm(double value) {
+ if (value <= 0) {
+ System.out.println("ERROR: Please enter a number larger than 0.");
+ return null;
+ } else {
+ return Math.log(value);
+ }
+ }
+
+ static String degreesRadians() {
+ System.out.println("Would you like you answer in Radians or Degrees?");
+ System.out.println("\"1\" - Radians");
+ System.out.println("\"2\" - Degrees");
+ String userInput = Console.getStringInput(":");
+ while (true)
+ switch (userInput) {
+ case "1":
+ return "Radians";
+ case "2":
+ return "Degrees";
+ default:
+ System.out.println("ERROR: Please enter \"1\" for Radians or \"2\" for Degrees.");
+ userInput = Console.getStringInput(":");
+ }
}
}
+
+
+
+
+
+
diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/FindAnAverage.java b/src/main/java/com/zipcodewilmington/scientificcalculator/FindAnAverage.java
new file mode 100644
index 00000000..f3222c2d
--- /dev/null
+++ b/src/main/java/com/zipcodewilmington/scientificcalculator/FindAnAverage.java
@@ -0,0 +1,37 @@
+package com.zipcodewilmington.scientificcalculator;
+
+public class FindAnAverage {
+ static void findAnAverage() {
+ double sumOfAverageInputs = 0;
+ System.out.println("How many numbers would you like to find an average of?");
+ System.out.println("Please enter \"return\" if you would like to quit.");
+ String userInputAverage = Console.getStringInput(":");
+ boolean correctInput;
+ //run a while loop that checks if a proper number was entered
+ while (true) {
+ correctInput = InputChecker.isNumeric(userInputAverage);
+ if (correctInput) break;
+ System.out.println("Enter your value");
+ userInputAverage = Console.getStringInput(":");
+ }
+ int userInputAverageInt = Integer.parseInt(userInputAverage);
+
+ for (int i = 1; i <= userInputAverageInt; i++) {
+ System.out.println("Enter a number.");
+ String averageInput = Console.getStringInput(":");
+ if(averageInput.equals("return")) break;
+ while (true) {
+ correctInput = InputChecker.isNumeric(averageInput);
+ if (correctInput) break;
+ System.out.println("Enter a number");
+ averageInput = Console.getStringInput(":");
+ }
+ Integer averageInputInt = Integer.parseInt(averageInput);
+ sumOfAverageInputs += averageInputInt;
+ }
+ double average = sumOfAverageInputs / userInputAverageInt;
+ System.out.println("You average is " + average + ".");
+ }
+ }
+
+
diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/InputChecker.java b/src/main/java/com/zipcodewilmington/scientificcalculator/InputChecker.java
new file mode 100644
index 00000000..ee9909e0
--- /dev/null
+++ b/src/main/java/com/zipcodewilmington/scientificcalculator/InputChecker.java
@@ -0,0 +1,13 @@
+package com.zipcodewilmington.scientificcalculator;
+
+public class InputChecker extends Calculator {
+ static boolean isNumeric(String str) {
+ try {
+ Double.parseDouble(str);
+ return true;
+ } catch(NumberFormatException e){
+ System.out.println("ERROR: Enter a valid number.");
+ return false;
+ }
+ }
+}
diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java
index 5f421325..878fa1ac 100644
--- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java
+++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java
@@ -1,17 +1,58 @@
package com.zipcodewilmington.scientificcalculator;
+import java.util.Arrays;
+import java.util.List;
+
/**
* Created by leon on 2/9/18.
*/
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 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);
+ boolean turnOn = true;
+ //make a list of basic commands for calculator
+ String[] basicCommands = {"1", "2", "3","4"};
+ //turn that array into a string
+ List basicCommandsList = Arrays.asList(basicCommands);
+
+
+
+ while (turnOn) {
+ System.out.println("Hello! Welcome to the calculator main menu!\nWould you care for a drink?\n\n");
+ System.out.println("What would you like to do?");
+ System.out.println("\"1\" - Run the Calculator");
+ System.out.println("\"2\" - Find an Average");
+ System.out.println("\"3\" - Fly to the Moon!!!");
+ System.out.println("\"4\" - Turn off the Calculator");
+ String userCommand = Console.getStringInput(":");
+
+ while (!basicCommandsList.contains(userCommand)) {
+ if (basicCommandsList.contains(userCommand)) {
+ break;
+ } else {
+ System.out.println("ERROR: Invalid command.\n");
+ }
+ System.out.println("What would you like to do?");
+ userCommand = Console.getStringInput(":");
+ }
+
+ switch (userCommand) {
+ case "1":
+ Calculator calculator = new Calculator();
+ calculator.runCalculator();
+ break;
+ case "2":
+ FindAnAverage.findAnAverage();
+ break;
+ case"3":
+ ToTheMoon.toTheMoon();
+ break;
+ case "4":
+ turnOn = false;
+ break;
+ }
+ }
+ System.out.println("Goodbye! Have a nice day!");
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ToTheMoon.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ToTheMoon.java
new file mode 100644
index 00000000..88bc0ff1
--- /dev/null
+++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ToTheMoon.java
@@ -0,0 +1,54 @@
+package com.zipcodewilmington.scientificcalculator;
+
+public class ToTheMoon {
+
+ static void toTheMoon() {
+ System.out.println("BLAST OFF! You're flying to the moon!\n");
+ System.out.println("Are you measuring your speed in km/h or mph?");
+ System.out.println("\"1\" - km/h");
+ System.out.println("\"2\" - mph");
+ String userInput = Console.getStringInput(":");
+
+ String whilePrompt = "On";
+ String mphKmh = "";
+ while (whilePrompt.equals("On"))
+ switch (userInput) {
+ case "1":
+ mphKmh = "kmh";
+ whilePrompt = "Off";
+ break;
+ case "2":
+ mphKmh = "mph";
+ whilePrompt = "Off";
+ break;
+ default:
+ System.out.println("ERROR: Please enter \"1\" for Km/H or \"2\" for mph.");
+ userInput = Console.getStringInput(":");
+ }
+ System.out.println("How fast are you traveling?");
+ String speedString = Console.getStringInput(":");
+
+ boolean correctInput;
+ //run a while loop that checks if a proper number was entered
+ while (true) {
+ correctInput = InputChecker.isNumeric(speedString);
+ if (correctInput) break;
+ System.out.println("Enter your value");
+ speedString = Console.getStringInput(":");
+ }
+ double speed = Double.parseDouble(speedString);
+
+ switch (mphKmh){
+ case "kmh":
+ double timeToMoon = 384000 / speed;
+ System.out.println("You will get to the moon in " + Math.round(timeToMoon) + " hours!");
+ break;
+ case "mph":
+ timeToMoon = 225623 / speed;
+ System.out.println("You will get to the moon in " + Math.round(timeToMoon) + " hours!");
+ break;
+ default:
+ System.out.println("Sorry. You're not going to the moon. You were just dreaming.");
+ }
+ }
+}
diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java
deleted file mode 100644
index 94e8d987..00000000
--- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.zipcodewilmington.scientific_calculator;
-
-/**
- * Created by leon on 2/9/18.
- */
-public class TestMainApplication {
-}
diff --git a/src/test/java/com/zipcodewilmington/scientificcalculator/ConsoleTest.java b/src/test/java/com/zipcodewilmington/scientificcalculator/ConsoleTest.java
new file mode 100644
index 00000000..86c12168
--- /dev/null
+++ b/src/test/java/com/zipcodewilmington/scientificcalculator/ConsoleTest.java
@@ -0,0 +1,510 @@
+package com.zipcodewilmington.scientificcalculator;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class ConsoleTest extends Console {
+
+ private Console result = new Console();
+
+ @Test
+ public void additionTest1() {
+ // given
+ double inputValue1 = 10.0;
+ double inputValue2 = 10.0;
+ double actual = inputValue1 + inputValue2;
+ // when
+ double expected = result.add(inputValue1, inputValue2);
+ // then
+ Assert.assertEquals(expected, actual, 0.0);
+ }
+
+ @Test
+ public void additionTest2() {
+ double inputValue1 = 5.0;
+ double inputValue2 = 5.0;
+ double actual = inputValue1 + inputValue2;
+ double expected = result.add(inputValue1, inputValue2);
+ Assert.assertEquals(expected, actual, 0.0);
+ }
+
+ @Test
+ public void additionTest3() {
+ double inputValue1 = 17.9;
+ double inputValue2 = 88.5;
+ double actual = inputValue1 + inputValue2;
+ double expected = result.add(inputValue1, inputValue2);
+ Assert.assertEquals(expected, actual, 0.0);
+ }
+
+ @Test
+ public void subtractionTest1() {
+ double inputValue1 = 2;
+ double inputValue2 = 3;
+ double actual = inputValue1 - inputValue2;
+ double expected = result.subtract(inputValue1, inputValue2);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void subtractionTest2() {
+ double inputValue1 = 3;
+ double inputValue2 = 2;
+ double actual = inputValue1 - inputValue2;
+ double expected = result.subtract(inputValue1, inputValue2);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void subtractionTest3() {
+ double inputValue1 = 97.4;
+ double inputValue2 = 44.3;
+ double actual = inputValue1 - inputValue2;
+ double expected = result.subtract(inputValue1, inputValue2);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void multiplicationTest1() {
+ double inputValue1 = 2;
+ double inputValue2 = 3;
+ double actual = inputValue1 * inputValue2;
+ double expected = result.multiply(inputValue1, inputValue2);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void multiplicationTest2() {
+ double inputValue1 = 7;
+ double inputValue2 = 3;
+ double actual = inputValue1 * inputValue2;
+ double expected = result.multiply(inputValue1, inputValue2);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void multiplicationTest3() {
+ double inputValue1 = 99.3;
+ double inputValue2 = 129.4545;
+ double actual = inputValue1 * inputValue2;
+ double expected = result.multiply(inputValue1, inputValue2);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void divideTest1() {
+ double inputValue1 = 4;
+ double inputValue2 = 2;
+ double actual = inputValue1 / inputValue2;
+ double expected = result.divide(inputValue1, inputValue2);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void divideTest2() {
+ double inputValue1 = 15;
+ double inputValue2 = 5;
+ double actual = inputValue1 / inputValue2;
+ double expected = result.divide(inputValue1, inputValue2);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void divideTest3() {
+ double inputValue1 = 34736.3463;
+ double inputValue2 = 8376346.235;
+ double actual = inputValue1 / inputValue2;
+ double expected = result.divide(inputValue1, inputValue2);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void exponent1() {
+ double inputValue1 = 2;
+ double inputValue2 = 3;
+ double actual = Math.pow(inputValue1, inputValue2);
+ double expected = result.exponent(inputValue1, inputValue2);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void exponent2() {
+ double inputValue1 = 7;
+ double inputValue2 = 3;
+ double actual = Math.pow(inputValue1, inputValue2);
+ double expected = result.exponent(inputValue1, inputValue2);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void exponent3() {
+ double inputValue1 = 357;
+ double inputValue2 = 23;
+ double actual = Math.pow(inputValue1, inputValue2);
+ double expected = result.exponent(inputValue1, inputValue2);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void cosineTest1() {
+ double inputValue = 45;
+ double actual = Math.cos(inputValue);
+ double expected = result.cosine(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void cosineTest2() {
+ double inputValue = 0;
+ double actual = Math.cos(inputValue);
+ double expected = result.cosine(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void cosineTest3() {
+ double inputValue = -180;
+ double actual = Math.cos(-inputValue);
+ double expected = result.cosine(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void factorialTest1() {
+ double inputValue = 5;
+ double actual = 1;
+ for (int i = 1; i <= inputValue; i++) {
+ actual = actual * i;
+ }
+ double expected = result.factorial(inputValue);
+ assertEquals(expected, actual, 0);
+ }
+
+ @Test
+ public void factorialTest2() {
+ double inputValue = 10;
+ double actual = 1;
+ for (int i = 1; i <= inputValue; i++) {
+ actual = actual * i;
+ }
+ double expected = result.factorial(inputValue);
+ assertEquals(expected, actual, 0);
+ }
+
+ @Test
+ public void factorialTest3() {
+ double inputValue = 1;
+ double actual = 1;
+ for (int i = 1; i <= inputValue; i++) {
+ actual = actual * i;
+ }
+ double expected = result.factorial(inputValue);
+ assertEquals(expected, actual, 0);
+ }
+
+ @Test
+ public void inverseTest1() {
+ double inputValue = 4;
+ double actual = 1 / inputValue;
+ double expected = result.inverse(inputValue);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void inverseTest2() {
+ double inputValue = 15;
+ double actual = 1 / inputValue;
+ double expected = result.inverse(inputValue);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void inverseTest3() {
+ double inputValue = 76;
+ double actual = 1 / inputValue;
+ double expected = result.inverse(inputValue);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void inverseCosineTest1() {
+ double inputValue = 1;
+ double actual = Math.acos(inputValue);
+ double expected = result.inverseCosine(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void inverseCosineTest2() {
+ double inputValue = -1;
+ double actual = Math.acos(inputValue);
+ double expected = result.inverseCosine(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void inverseCosineTest3() {
+ double inputValue = 0;
+ double actual = Math.acos(inputValue);
+ double expected = result.inverseCosine(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void inverseLogarithmTest1() {
+ double inputValue = 1;
+ double actual = Math.pow(10, inputValue);
+ double expected = result.inverseLogarithm(inputValue);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void inverseLogarithmTest2() {
+ double inputValue = 45;
+ double actual = Math.pow(10, inputValue);
+ double expected = result.inverseLogarithm(inputValue);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void inverseLogarithmTest3() {
+ double inputValue = 180;
+ double actual = Math.pow(10, inputValue);
+ double expected = result.inverseLogarithm(inputValue);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void inverseNaturalLogarithmTest1() {
+ double inputValue = 1;
+ double actual = Math.exp(inputValue);
+ double expected = result.inverseNaturalLogarithm(inputValue);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void inverseNaturalLogarithmTest2() {
+ double inputValue = 45;
+ double actual = Math.exp(inputValue);
+ double expected = result.inverseNaturalLogarithm(inputValue);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void inverseNaturalLogarithmTest3() {
+ double inputValue = -180;
+ double actual = Math.exp(inputValue);
+ double expected = result.inverseNaturalLogarithm(inputValue);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void inverseSineTest1() {
+ double inputValue = 1;
+ double actual = Math.asin(inputValue);
+ double expected = result.inverseSine(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void inverseSineTest2() {
+ Console result = new Console();
+ double inputValue = -1;
+ double actual = Math.asin(inputValue);
+ double expected = result.inverseSine(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void inverseSineTest3() {
+ double inputValue = 0;
+ double actual = Math.asin(inputValue);
+ double expected = result.inverseSine(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void inverseTangentTest1() {
+ double inputValue = 90;
+ double actual = Math.atan(inputValue);
+ double expected = result.inverseTangent(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void inverseTangentTest2() {
+ double inputValue = 0;
+ double actual = Math.atan(inputValue);
+ double expected = result.inverseTangent(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void inverseTangentTest3() {
+ double inputValue = -180;
+ double actual = Math.atan(inputValue);
+ double expected = result.inverseTangent(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void invertTest1() {
+ double inputValue = 2;
+ double actual = -1 * inputValue;
+ double expected = result.invert(inputValue);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void invertTest2() {
+ double inputValue = 17;
+ double actual = -1 * inputValue;
+ double expected = result.invert(inputValue);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void invertTest3() {
+ double inputValue = 361.25;
+ double actual = -1 * inputValue;
+ double expected = result.invert(inputValue);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void LogarithmTest1() {
+ double inputValue = 1;
+ double actual = Math.log10(inputValue);
+ double expected = result.logarithm(inputValue);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void LogarithmTest2() {
+ double inputValue = 45;
+ double actual = Math.log10(inputValue);
+ double expected = result.logarithm(inputValue);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void LogarithmTest3() {
+ double inputValue = 180;
+ double actual = Math.log10(inputValue);
+ double expected = result.logarithm(inputValue);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void sineTest1() {
+ double inputValue = 90;
+ double actual = Math.sin(inputValue);
+ double expected = result.sine(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void sineTest2() {
+ double inputValue = 45;
+ double actual = Math.sin(inputValue);
+ double expected = result.sine(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void sineTest3() {
+ double inputValue = -180;
+ double actual = Math.sin(-inputValue);
+ double expected = result.sine(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void sqrt1() {
+ double inputValue1 = 2;
+ double actual = Math.sqrt(inputValue1);
+ double expected = result.sqrt(inputValue1);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void sqrt2() {
+ double inputValue1 = 7;
+ double actual = Math.sqrt(inputValue1);
+ double expected = result.sqrt(inputValue1);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void sqrt3() {
+ double inputValue1 = 9;
+ double actual = Math.sqrt(inputValue1);
+ double expected = result.sqrt(inputValue1);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void squaredTest1() {
+ double inputValue = 2;
+ double actual = inputValue * inputValue;
+ double expected = result.squared(inputValue);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void squaredTest2() {
+ double inputValue = 7;
+ double actual = inputValue * inputValue;
+ double expected = result.squared(inputValue);
+ assertEquals(expected, actual, .00);
+ }
+
+ @Test
+ public void tangentTest1() {
+ double inputValue = 45;
+ double actual = Math.tan(inputValue);
+ double expected = result.tangent(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void tangentTest2() {
+ double inputValue = 90;
+ double actual = Math.tan(inputValue);
+ double expected = result.tangent(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void tangentTest3() {
+ double inputValue = -180;
+ double actual = Math.tan(-inputValue);
+ double expected = result.tangent(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+ @Test
+ public void naturalLogarithmTest1() {
+ double inputValue = 7;
+ double actual = Math.log(inputValue);
+ double expected = result.naturalLogarithm(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void naturalLogarithmTest2() {
+ double inputValue = 3;
+ double actual = Math.log(inputValue);
+ double expected = result.naturalLogarithm(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+
+ @Test
+ public void naturalLogarithmTest3() {
+ double inputValue = 1;
+ double actual = Math.log(inputValue);
+ double expected = result.naturalLogarithm(inputValue);
+ assertEquals(expected, actual, .00000);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/com/zipcodewilmington/scientificcalculator/InputCheckerTest.java b/src/test/java/com/zipcodewilmington/scientificcalculator/InputCheckerTest.java
new file mode 100644
index 00000000..19870761
--- /dev/null
+++ b/src/test/java/com/zipcodewilmington/scientificcalculator/InputCheckerTest.java
@@ -0,0 +1,29 @@
+package com.zipcodewilmington.scientificcalculator;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class InputCheckerTest extends InputChecker {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void isNumericTest1() {
+ boolean actual = InputChecker.isNumeric("213");
+ assertTrue(actual);
+ }
+ @Test
+ public void isNumericTest2() {
+ boolean actual = InputChecker.isNumeric("pony");
+ assertFalse(actual);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/com/zipcodewilmington/scientificcalculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientificcalculator/TestMainApplication.java
new file mode 100644
index 00000000..461ca103
--- /dev/null
+++ b/src/test/java/com/zipcodewilmington/scientificcalculator/TestMainApplication.java
@@ -0,0 +1,7 @@
+package com.zipcodewilmington.scientificcalculator;
+
+/**
+ * Created by leon on 2/9/18.
+ */
+public class TestMainApplication extends MainApplication {
+}