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

I created simplecalculation #18

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
21 changes: 3 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,14 @@
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
*/
public class Console {

public static void defaultValue (){
System.out.println(SimpleCalculator.intResult);
}


public static void print(String output, Object... args) {
System.out.printf(output, args);
}
Expand All @@ -22,11 +27,17 @@ public static String getStringInput(String prompt) {
return userInput;
}

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

public static Double getDoubleInput(String prompt) {
return null;
public static Double getDoubleInput() {
Scanner scan = new Scanner(System.in);
double d = scan.nextDouble();
return d;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,35 @@
* 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.defaultValue();
// 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 double", d);
//
//
//
//// SimpleCalculator simpleCalculation = new SimpleCalculator();
//// double dd = simpleCalculation.calculator('*',i,d);
//
//
//
// System.out.println("Result = "+ScientificCalculator.cosine(d));

StartCalculatorWithType.start();







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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.zipcodewilmington.scientificcalculator;

public class ScientificCalculator {

public double square(double x){
return x * x;
}

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

public double inverse(double x) {
return 1 / x;
}

public double switchSign(double x) {
return -x;
}

public double sine(double x) {
return Math.sin(x);
}

public double cosine(double x) {
return Math.cos(x);
}

public double tangent(double x) {
return Math.tan(x);
}

public double inverseSine(double x) {
return Math.asin(x);
}

public double inverseCosine(double x) {
return Math.acos(x);
}

public double inverseTangent(double x) {
return Math.atan(x);
}

public double factorial(double x) {
if (x == 0) {
return 1;
}
else{
int result = 1;
for (int i = 1;i<=x;i++){
result*=i;
}
return result;
}

}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package com.zipcodewilmington.scientificcalculator;

public class SimpleCalculator {


public static double doubleResult;
public static int intResult;

public SimpleCalculator(){
this.intResult = 0;
}


public double calculator(char operator, double num1, double num2) {

if (operator == '+') {
doubleResult = num1 + num2;
}


else if (operator == '-') {
if (num1 > num2) {
doubleResult = num1 - num2;
} else {
doubleResult = -num2 -(- num1);
}
}
else if (operator == '*') {
if(num1<0 || num2<0){
doubleResult = -num1 * num2;
}
else {
doubleResult = num1 * num2;
}

}
else if (operator == '%') {
doubleResult = num1 % num2;
}
else {
try {

doubleResult = num1 / num2;


} catch (ArithmeticException e) {
System.out.println("Error " + e.getMessage());
}

}
return doubleResult;
}



public double calculator(char operator, int num1, double num2) {
if (operator == '+') {
doubleResult = num1 + num2;
} else if (operator == '-') {
if (num1 > num2) {
doubleResult = num1 - num2;
} else {
doubleResult = num2 - num1;
}
}
else if (operator == '%') {
doubleResult = num1 % num2;
}
else if (operator == '*') {
doubleResult = num1 * num2;
} else {
try {
doubleResult = num1 / num2;

} catch (ArithmeticException e) {
System.out.println("Exception handled " + e.getMessage());
}

}
return doubleResult;
}

public double calculator(char operator, double num1, int num2) {
if (operator == '+') {
doubleResult = num1 + num2;
} else if (operator == '-') {
if (num1 > num2) {
doubleResult = num1 - num2;
}
else if (operator == '%') {
doubleResult = num1 % num2;
}
else {
doubleResult = num2 - num1;
}
}
else if (operator == '*') {
doubleResult = num1 * num2;
} else {
try {

doubleResult = num1 / num2;

} catch (ArithmeticException e) {
System.out.println("Exception handled " + e.getMessage());
}

}
return doubleResult;
}

public double calculator(char operator, int num1, int num2) {
if (operator == '+') {
doubleResult = num1 + num2;
} else if (operator == '-') {
if (num1 > num2) {
doubleResult = num1 - num2;
}
else {
doubleResult = num2 - num1;
}
} else if (operator == '*') {
doubleResult = num1 * num2;
}

else if (num1 > num2) {
try{
doubleResult = num1 / num2;
}
catch (ArithmeticException e){
System.out.println("Can't divide by zero");
}


}
else if (num2 < num1) {
try{
doubleResult = num2 / num1;
}
catch (ArithmeticException e){
return Double.parseDouble("Error");
}
}

return doubleResult;



}
}
Loading