Demonstrating Method Overloading

master
sgoudham 4 years ago
parent 0931d91922
commit dd0c3c73d1
No known key found for this signature in database
GPG Key ID: EF51A29A50FB754C

@ -23,7 +23,7 @@ public class MathEquation {
} }
// Method to execute the calculations // Method to execute the calculations
void execute() { public void execute() {
switch (this.opCode) { switch (this.opCode) {
case 'a': case 'a':
this.result = this.leftVal + this.rightVal; this.result = this.leftVal + this.rightVal;
@ -46,6 +46,22 @@ public class MathEquation {
sumOfResults += result; sumOfResults += result;
} }
public void execute(double leftVal, double rightVal) {
this.leftVal = leftVal;
this.rightVal = rightVal;
execute();
}
public void execute(int leftVal, int rightVal) {
this.leftVal = leftVal;
this.rightVal = rightVal;
execute();
result = (int) result;
}
public static double getAverageResult() { public static double getAverageResult() {
return sumOfResults / numOfCalculations; return sumOfResults / numOfCalculations;
} }

Loading…
Cancel
Save