Created
March 21, 2016 20:05
-
-
Save alexejVasko/959e3cc1643040db0e90 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package calculator; | |
public class Calculator { | |
// public static String num1 = null; | |
public static String num2 = null; | |
public static double v1 = 0; | |
public static double value2 = 0; | |
public static double ChooseCalculateMethod = 0; | |
public static void main(String[] args) { | |
System.out.println("Please, enter the first number "); | |
MyScanner num1 = new MyScanner(); | |
String firstValue = num1.scanString(); | |
v1 = Double.parseDouble(firstValue); | |
System.out.println("num1 = " + v1); | |
MyScanner scannerSign = new MyScanner(); | |
System.out.println("Please, enter the type of operation "); | |
while (true) { | |
String mySign = scannerSign.scanString(); | |
if (mySign.equals("*")) { | |
CalculateMethods multiplicateMe = new CalculateMethods(); | |
multiplicateMe.multiplication(); | |
ChooseCalculateMethod = 1; | |
break; | |
} else if (mySign.equals("/")) { | |
CalculateMethods divideMe = new CalculateMethods(); | |
divideMe.division(); | |
ChooseCalculateMethod = 2; | |
break; | |
} else if (mySign.equals("+")) { | |
CalculateMethods addMe = new CalculateMethods(); | |
addMe.addition(); | |
ChooseCalculateMethod = 3; | |
break; | |
} else if (mySign.equals("-")) { | |
CalculateMethods subtractMe = new CalculateMethods(); | |
subtractMe.subtraction(); | |
ChooseCalculateMethod = 4; | |
break; | |
} else { | |
System.out.println("try again.."); | |
} | |
} | |
MyScanner scanner2 = new MyScanner(); | |
System.out.println("Please, enter the second number "); | |
num2 = scanner2.scanString(); | |
value2 = Double.parseDouble(num2); | |
System.out.println("num2 = " + value2); | |
System.out.println("---------------------------------------"); | |
CalculateResult stepResult = new CalculateResult(); | |
double cycleResult = stepResult.calcResult(ChooseCalculateMethod); | |
System.out.println("result = " + cycleResult); | |
} | |
} |
package calculator;
public class CalculateResult extends Calculator {
public double calcResult(double ChooseCalculateMethod) {
double a = ChooseCalculateMethod;
if(a == 1){
a = Calculator.v1*Calculator.value2;
}else if (a == 2){
a = Calculator.v1/Calculator.value2;
}else if (a == 3){
a = Calculator.v1+Calculator.value2;
}else if (a == 4){
a = Calculator.v1-Calculator.value2;
}
return a;
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
package calculator;
public class CalculateMethods {
}