Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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,100 @@
package com.zipcodewilmington.scientificcalculator;
import java.lang.Math;
public class Calculator {

private double display;

public Calculator() {
this.display = 0;
}

public double getDisplay() {
return this.display;
}

public void clearDisplay() {
this.display = 0;
}

public void setDisplay(double number) {
this.display = number;
}

public static double addTwoNums(double x, double y) {
double sum = x + y;
Console.print("The sum of " + x + " and " + y + " is " + String.valueOf(sum));
return sum;
}

public static double subtractTwoNums(double x, double y) {
double difference = x - y;
Console.print("The difference of " + x + " and " + y + " is " + String.valueOf(difference));
return difference;
}

public static double multiplyTwoNums(double x, double y) {
double product = x * y;
Console.print("The product of " + x + " and " + y + " is " + String.valueOf(product));
return product;
}

public static double divide(double x, double y) {
double quotient = 0;
if (y != 0) {
quotient = x /y;
} else {
//this.display = Double.NaN; // Set display to NaN for division by zero error
}
Console.print("The quotient of " + x + " / " + y + " is " + String.valueOf(quotient));
return quotient;
}

public static double square(double x) {
double squared = (x * x);
Console.print(x + " :Squared is " + String.valueOf(squared));
return squared;
}

public static double squareRoot(double x) {
double squareRoot = Math.sqrt(x);
Console.print( "The square root of: " + x + " is " + String.valueOf(squareRoot));
return squareRoot;
}

public static double exponentiation(double x, double y) {
double total = Math.pow(x , y);

Console.print(x + " raised to the power of " + y + " is " + total );
return total;
}

public void inverse() {
if (this.display != 0) {
this.display = 1 / this.display;
} else {
//this.display = Double.NaN; // Set display to NaN for division by zero error

}
}

public static double invertSign(double x) {
double newNum = 0;
if (x < 0 ){
//x is less than in this scenario
newNum = (x * -1);
} else {
newNum = -x;

}
Console.print("This number with it's sign inverted is: " + newNum);
return newNum;
}

public void clearError() {
if (Double.isNaN(this.display)) {
this.display = 0;
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ public static String getStringInput(String prompt) {
}

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

public static Double getDoubleInput(String prompt) {
return null;
Scanner scanner = new Scanner(System.in);
print(prompt);
double userInput = scanner.nextDouble();
return userInput;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.zipcodewilmington.scientificcalculator;

import java.util.Scanner;

public class CoreFeatures {
public static void main(String[] args) {
/*
Console.println("Welcome to Halictidae Calculator!");
Console.println("I'm here to help!");

// String s = Console.getStringInput("Enter a string");
// Integer i = Console.getIntegerInput("Enter an integer");
// Double d = Console.getDoubleInput("Enter a double.");
// String methodName = Console.getStringInput("Enter a function");
// String firstNumber = Console.getStringInput("Enter the first number");
//
// 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);

int result = 1;
/*
Console.println("Welcome to Halictidae Calculator!");
Console.println("I'm here to help!");
int numberOne = Console.getIntegerInput("Enter the first number: ");
int numberTwo = Console.getIntegerInput("Enter the Second number: ");
String chooseOperation = Console.getStringInput("What operation?\n" +
"( + ) ( - ) ( * ) ( / ) ( ^ ) ( sqr ) ( sqrt )\n");*/

//initialized variable result
//Scanner scanObject = new Scanner(System.in);


/*
Scanner scan = new Scanner(System.in);
System.out.println("Enter first number:");
//enter first number
numberOne = (int) scan.nextDouble();
System.out.println("What operation?");
System.out.println("( + ) ( - ) ( * ) ( / ) ( ^ ) ( sqr ) ( sqrt )");
//choose specified operation of choice
String operator = scanObject.next();
System.out.println("Enter second number");
//enter second number
numberTwo = scan.nextInt(); */


//System.out.println(result);
//results printed

/*
switch (chooseOperation) {
case "+":
result = number one + number two;
break;
case "-":
result = numberOne - numberTwo;
break;
case "*":
result = numberOne * numberTwo;
break;
case "/":
result = numberOne / numberTwo;
break;
case "^":
result = (int) Math.pow(numberOne, numberTwo);
break;
case "sqrt":
result = (int) Math.sqrt(numberOne);
break;

//switch statement - block of code executed when switch value matches operation chosen
}
//System.out.println(numberOne + " " + chooseOperation + " " + numberTwo + " = " + result);
// Example: 10 + 5 = 15 (different operations can be chosen)
}

*/
}
}








Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,106 @@
*/
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("Welcome to Halictidae Calculator!");
Console.println("I'm here to help!");
String chooseOperation = Console.getStringInput("What operation would you like to perform today?\n" +
"( + ) ( - ) ( * ) ( / ) ( ^ ) ( sqr ) ( sqrt ) (exponentiation) (invert sign)\n" +
"(sine) (cosine) (tangent) (inverseSine) (inverseCosine) (inverseTangent) (log) (inverseLog)" +
" (naturalLog) (inverseNaturalLog) (factorial)\n" +
"(clearError)" +
"\nPlease type it in as you see in the parentheses ---> ");

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);
double numberOne;
double numberTwo;

switch (chooseOperation) {
case "+":
numberOne = Console.getDoubleInput("Please enter first number: ");
numberTwo = Console.getDoubleInput("Please enter second number: ");
Calculator.addTwoNums(numberOne, numberTwo);
break;
case "-":
numberOne = Console.getDoubleInput("Please enter first number: ");
numberTwo = Console.getDoubleInput("Please enter second number: ");
Calculator.subtractTwoNums(numberOne, numberTwo);
break;
case "*":
numberOne = Console.getDoubleInput("Please enter first number: ");
numberTwo = Console.getDoubleInput("Please enter second number: ");
Calculator.multiplyTwoNums(numberOne, numberTwo);
break;
case "/":
numberOne = Console.getDoubleInput("Please enter first number: ");
numberTwo = Console.getDoubleInput("Please enter second number: ");
Calculator.divide(numberOne, numberTwo);
break;
case "exponentiation":
numberOne = Console.getDoubleInput("Please enter first number: ");
numberTwo = Console.getDoubleInput("Please enter second number: ");
Calculator.exponentiation(numberOne, numberTwo);
break;
case "sqr":
numberOne = Console.getDoubleInput("Please enter the number you want squared: ");
Calculator.square(numberOne);
break;
case "sqrt":
numberOne = Console.getDoubleInput("Please enter the number you want the square root of: ");
Calculator.squareRoot(numberOne);
break;
case "invert sign":
numberOne = Console.getDoubleInput("Please enter the number which sign you want to inverse: ");
Calculator.invertSign(numberOne);
break;
case "sine":
numberOne = Console.getDoubleInput("Please enter the number you want to Sine of: ");
Science.Sin(numberOne);
break;
case "cosine":
numberOne = Console.getDoubleInput("Please enter the number you want to Cosine of: ");
Science.Cos(numberOne);
break;
case "tangent":
numberOne = Console.getDoubleInput("Please enter the number you want to Tangent of: ");
Science.Tan(numberOne);
break;
case "inverseSine":
numberOne = Console.getDoubleInput("Please enter the number you want to Inverse Sine of: ");
Science.aSin(numberOne);
break;
case "inverseCosine":
numberOne = Console.getDoubleInput("Please enter the number you want to Inverse Cosine of: ");
Science.aCos(numberOne);
break;
case "inverseTangent":
numberOne = Console.getDoubleInput("Please enter the number you want to Inverse Tangent of: ");
Science.aTan(numberOne);
break;
case "log":
numberOne = Console.getDoubleInput("Please enter the number you want the log of: ");
Science.log(numberOne);
break;
case "inverseLog":
numberOne = Console.getDoubleInput("Please enter the number you want the inverse log of: ");
Science.invLog(numberOne);
break;
case "naturalLog":
numberOne = Console.getDoubleInput("Please enter the number you want the natural log of: ");
Science.natLog(numberOne);
break;
case "inverseNaturalLog":
numberOne = Console.getDoubleInput("Please enter the number you want the inverse natural log of: ");
Science.invNatLog(numberOne);
break;
case "factorial":
numberOne = Console.getDoubleInput("Please enter the number you want the factorial of: ");
Science.factorial(numberOne);
break;
default:
Console.print("That command does not exist please enter another command: ");
break;
}
}
}



Loading