

The following Java program shown in Figure 2 returns compile time error. Identify all the errors and correct them. Do not write the entire program. You are not allowed to add or remove any line from the given program to produce the expected output. Your task is to mention the line numbers which are incorrect and then write the required changes in those lines to get the following output: 5.0 12.0 50.0 60.0 1 interface DoubleOperator{ 2 double apply (double x, double y); 3} 4 5 enum Operations [ 6 ADD ((x, y)-> (x + y), "+"), 7 SUBTRACT ((x, y) -> ( x - y), "-"), 8 MULTIPLY ((x, y) -> ( x * y), "*"), 9 DIVIDE ((x, y) -> (x/y), "/"); 10 11 private DoubleOperator function; 12 private String Op; 13 14 public Operations (DoubleOperator function, String Op) { this.function = function; 15 16 this.Op = Op; 17 } 18 19 public String getFunction() { 20 return function; 21 } 22 23 public String get0p() { return Op; } 24 ] 25 26 public class Calculator { 27 static String OPERATORS "+-x/"; 28 29 public static Operations getOperator (String s) { 30 if (!OPERATORS.contains (s)) return null; 31 32 for (Operations op: Operations.values()) { if (s op.getop()) 33 34 return op; 35 }
36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 } return 0; } public static double evaluateString (String input) { String[] expression input.split(" "); if (expression.size() != 3) return 0; double x = Double.parseDouble (expression [0]); double y = Double.parseDouble (expression[2]); Operations op getoperator (expression[1]); if (op== null) return 0; return calc(x, y, op); } public static double calc(double x, double y, Operations operation) { return operation.apply(x, y); } public static void main(String[] args) { String s1 "10 / 2"; String s2 = "2+ 10"; String s3= "100 50"; String s4= "2 * 30"; System.out.println(evaluateString(s1)); System.out.println(evaluateString(s2)); System.out.println(evaluateString(s3)); System.out.println(evaluateString($4)); }