Addes separate classes/interfaces for Operations

master
sgoudham 4 years ago
parent 1a99a6dca4
commit 5642dbd575
No known key found for this signature in database
GPG Key ID: EF51A29A50FB754C

@ -0,0 +1,28 @@
public class Adder extends CalculateBase implements MathProcessing {
public Adder() {}
public Adder(double leftVal, double rightVal) {
super(leftVal, rightVal);
}
@Override
public void calculate() {
setResult(getLeftVal() + getRightVal());
}
// Using interfaces
@Override
public String getKeyWord() {
return "add";
}
@Override
public double doCalculation(double leftVal, double rightVal) {
setLeftVal(leftVal);
setRightVal(rightVal);
calculate();
return getResult();
}
}

@ -0,0 +1,13 @@
public class Divider extends CalculateBase {
public Divider() {}
public Divider(double leftVal, double rightVal) {
super(leftVal, rightVal);
}
@Override
public void calculate() {
setResult(getLeftVal() / getRightVal());
}
}

@ -0,0 +1,13 @@
public class Multiplier extends CalculateBase {
public Multiplier() {}
public Multiplier(double leftVal, double rightVal) {
super(leftVal, rightVal);
}
@Override
public void calculate() {
setResult(getLeftVal() * getRightVal());
}
}

@ -0,0 +1,21 @@
public class PowerOf implements MathProcessing {
private String formattedOutput;
@Override
public String getKeyWord() {
return "power";
}
@Override
public String doFormatting() {
return formattedOutput;
}
@Override
public double doCalculation(double leftVal, double rightVal) {
double product = Math.pow(leftVal, rightVal);
formattedOutput = leftVal + " Has Been Raised To The Power Of " + rightVal + " Which Results In: " + product;
return product;
}
}

@ -0,0 +1,13 @@
public class Subtractor extends CalculateBase {
public Subtractor() {}
public Subtractor(double leftVal, double rightVal) {
super(leftVal, rightVal);
}
@Override
public void calculate() {
setResult(getLeftVal() - getRightVal());
}
}
Loading…
Cancel
Save