From dd0c3c73d11fb983d93e334033a978053b137eeb Mon Sep 17 00:00:00 2001 From: sgoudham Date: Sun, 11 Oct 2020 01:02:30 +0100 Subject: [PATCH] Demonstrating Method Overloading --- .../New Calc Engine/src/MathEquation.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Java Classes & Interfaces/New Calc Engine/src/MathEquation.java b/Java Classes & Interfaces/New Calc Engine/src/MathEquation.java index f6f17ff..dbe2e3d 100644 --- a/Java Classes & Interfaces/New Calc Engine/src/MathEquation.java +++ b/Java Classes & Interfaces/New Calc Engine/src/MathEquation.java @@ -23,7 +23,7 @@ public class MathEquation { } // Method to execute the calculations - void execute() { + public void execute() { switch (this.opCode) { case 'a': this.result = this.leftVal + this.rightVal; @@ -46,6 +46,22 @@ public class MathEquation { 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() { return sumOfResults / numOfCalculations; }