Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scientific calc project C Poteat T Die C Tong #111

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
<groupId>com.zipcodewilmington</groupId>
<artifactId>scientific_calculator</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>


</project>
Original file line number Diff line number Diff line change
@@ -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;}

}



Original file line number Diff line number Diff line change
@@ -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);

}


}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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.










Loading