Created
January 5, 2018 16:20
-
-
Save aorjoa/ef8b66625ee3cfbbe34ccade96791612 to your computer and use it in GitHub Desktop.
This file contains 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 oot.lab8; | |
public class Calculator implements MathCalculator { | |
private double operand1; | |
private double operand2; | |
public Calculator(double operand1, double operand2){ | |
this.operand1 = operand1; | |
this.operand2 = operand2; | |
} | |
public double add() { | |
return operand1 + operand2; | |
} | |
public double minus() { | |
return operand1 - operand2; | |
} | |
public void compare() { | |
if(operand1 > operand2) { | |
System.out.println(operand1 + " > " + operand2 + " : " + (operand1-operand2)); | |
} else { | |
System.out.println(operand1 + " <= " + operand2 + " : " + (operand2-operand1)); | |
} | |
} | |
} |
package oot.lab8;
/**
* Created by Bhuridech Sudsee.
*/
public interface MathCalculator {
public double add();
public double minus();
}
package oot.lab8;
import java.util.Scanner;
/**
* Created by Bhuridech Sudsee.
*/
public class Lab8Sec1 {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
System.out.print("Enter number with operator : ");
String calText = scanner.nextLine();
String[] calTextSplit = calText.split(" ");
double firstOperand = Double.valueOf(calTextSplit[0]);
String operator = calTextSplit[1];
double secondOperand = Double.valueOf(calTextSplit[2]);
Calculator c = new Calculator(firstOperand, secondOperand);
switch (operator){
case "ADD":
System.out.println(calText + " = "+ c.add());
break;
case "MINUS":
System.out.println(calText + " = "+ c.minus());
break;
}
c.compare();
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
package oot.lab8;
/**
*/
public interface MathCalculator {
public double add();
public double minus();
}