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

Pull#3 Testing update #5

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b39223c
coded switchDisplayMode method
Jun 25, 2022
a477bd4
updated to 18 compatibility
Jun 25, 2022
e8295de
modified switchDisplayMode method to work more accurately
Jun 25, 2022
3e3c020
Merge pull request #1 from TamyahD/scientificFeats
TamyahD Jun 25, 2022
2bda0ab
Revert "Scientific feats"
TamyahD Jun 25, 2022
3ddcc7f
Merge pull request #2 from ZC8-3-1-team1group3/revert-1-scientificFeats
TamyahD Jun 25, 2022
92c2e03
basic 6 operations in, no inputs. test case
jjheffernan Jun 26, 2022
47adb66
Merge branch 'ZC8-3-1-team1group3:master' into master
jjheffernan Jun 26, 2022
de1e022
Merge pull request #7 from jjheffernan/master
jjheffernan Jun 26, 2022
0dd83ec
added exponent of x^y
jjheffernan Jun 26, 2022
7b9e0fa
added invert sign functionality
jjheffernan Jun 26, 2022
6b1fb4b
Merge pull request #9 from ZC8-3-1-team1group3/calc-core
jjheffernan Jun 26, 2022
83e4431
start implementation of activecalc Boolean, and default state var
jjheffernan Jun 26, 2022
ec511ae
added getCharAt method for switch statement functionality within calc…
jjheffernan Jun 26, 2022
e362054
all basic operators within test case
jjheffernan Jun 27, 2022
68c9d45
updated getIntegerInput, getDoubleInput, and fixed getCharInput
jjheffernan Jun 27, 2022
69d113e
Merge pull request #13 from ZC8-3-1-team1group3/calc-core
jjheffernan Jun 27, 2022
0629f3d
cleaned up operator code
jjheffernan Jun 27, 2022
45eb8e2
added printf support to Arithmetic object
jjheffernan Jun 27, 2022
31a9bc1
Merge pull request #17 from ZC8-3-1-team1group3/calc-core
jjheffernan Jun 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package com.zipcodewilmington.scientificcalculator;

import java.io.Console;
import java.lang.Math;


public class Calculator {
Double x, y, mem, result;
String ans;
String choiceString = "+";
// MainApplication activeCalc = new MainApplication();

// Input section
public void Arithmetic(String[] args) {
switch (choiceString) {
// Case 1
case "+" -> {
// Print statement corresponding case

// break keyword terminates the
result = add(x, y);
System.out.printf("adding %.4f and %.4f",x,y);
}
// Case 2
case "-" -> {
// Print statement corresponding case
result = subtract(x, y);
System.out.printf("subtracting %.4f from %.4f gives",y,x,result);
}

// Case 3
case "*" -> {
// Print statement corresponding case
result = multiply(x, y);
System.out.printf("multiplying %.4f by %.4f gives",x,y,result);
}
// Case 4
case "/" -> {
// Print statement corresponding case
result = divide(x,y);
System.out.printf("dividing %.4f by %.4f gives %.4f",x,y,result);
}
case "square" -> {
// Print statement corresponding case
result = sqr(x);
System.out.printf("the square of %.4f is %.4f",x,result);
}
case "sqrt" -> {
// Print statement corresponding case
result = root(x);
System.out.printf("the square root of %.4f is %.4f",x,result);
}
case "1/x" -> {
// Print statement corresponding case
result = inverse(x);
System.out.printf("the inverse of %.4f is %.4f",x,result);
}
case "+/-" -> {
// Print statement corresponding case
result = invertSign(x);
System.out.printf("reversed sign: %.4f",result);
}
case "x^y" -> {
// Print statement corresponding case
result = sqrY(x, y);
System.out.printf("%.4f to the power of %.4f is %.4f",x,y,result);
}
default ->
// Print statement corresponding case
System.out.println("Err, no match");
}
ans = String.format(String.valueOf(result));

}


// Operator Choice

// System.out.println("Choose an operator from '+' '-' '*' '/' '^sq' '^exp' '^y' '^neg 'inv'");

public double add(double x, double y) {
return x + y;
}

public double subtract(double x, double y) {
return x - y;
}

public double multiply(double x, double y) {
return x * y;
}

public double divide(double x, double y) {
return x / y;
}

public double sqr(double x) {
return Math.pow(x, 2); //
}

public double sqrY(double x, double y) {
return Math.pow(x, y);
}

public double root(double x) {
return Math.sqrt(x);
}

public double inverse(double x) {
return Math.expm1(x);
}

public double invertSign(double x) {
return x*-1;
}


///////////////// refer to private functions here

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,25 @@ public static String getStringInput(String prompt) {
return userInput;
}

public static Integer getIntegerInput(String prompt) {
return null;
public static char getCharInput(String prompt) {
Scanner scanner = new Scanner(System.in);
println(prompt);
char userInput = scanner.next().charAt(0);
return userInput;
}

public static int getIntegerInput(String prompt) {
Scanner scanner = new Scanner(System.in);
println(prompt);
String userInput = String.valueOf(scanner.nextInt());
return Integer.parseInt(userInput);
}

public static Double getDoubleInput(String prompt) {
return null;
public static double getDoubleInput(String prompt) {
//while (!prompt.)
Scanner scanner = new Scanner(System.in);
println(prompt);
double userInput = scanner.nextDouble();
return userInput;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* Created by leon on 2/9/18.
*/
public class MainApplication {

boolean activeCalc = true;

public static void main(String[] args) {
Console.println("Welcome to my calculator!");
String s = Console.getStringInput("Enter a string");
Expand Down