It receives two double numbers and an operation to be performed on these numbers. This operation could be PLUS, MINUS, TIMES or DIVIDES. (Define an “enum” with these operations.) The method should return a double with the result.
I dont know what to write for it to test properly in main, and im not sure if the code runs correctly. Does it?
public class Perform { public enum Operation { PLUS, MINUS, TIMES, DIVIDES } private static Operation _operation; double result; double num1; double num2; public Perform(Operation _operation) { this._operation = _operation; } public Operation getOperation() { return _operation; } public void setOperation(Operation anOperation) { this._operation = anOperation; } public static double theResult (double input1, double input2, Operation aOperation) { double temp1 = input1; double temp2 = input2; _operation = aOperation; switch(_operation) { case PLUS: return temp1 + temp2; case MINUS: return temp1 - temp2; case TIMES: return temp1 * temp2; case DIVIDES: return temp1/temp2; default: return -1; } } public static void main(String[] args) { Perform p = new Perform(2.0, 2.0, PLUS); System.out.println(" 2 + 2 = " + p.theResult( 2.0, 2.0 ) ); } }