Question: The following code has numerous errors that need to be fixed. // LabProgram.java import java.util.Scanner; public class LabProgram { public static void main(String[] args) {
The following code has numerous errors that need to be fixed.
// LabProgram.java
import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Calculator calc = new Calculator(); Scanner keyboard = new Scanner(System.in); double num1 = keyboard.nextDouble(); double num2 = keyboard.nextDouble; // 1. The initial value System.out.println(calc.getValue()); // 2. The value after adding num1 calc.add(num1); System.out.println( .getValue()); // 3. The value after multiplying by 3 calc.multiply(3); System.out.println(calc. ()); // 4. The value after subtracting num2 calc.subtract(num2); System.out.println(calc.Value()); // 5. The value after dividing by 2 calc.divide(2); System.out.println(calc getValue()); // 6. The value after calling the clear() method calc.clear(); System.out.println(calc.getValue(); } }
// Calculator.java
public class Calculator { private double value; public Calculator() { clear(); } public void add(double val) { value += val; public void subtract(double val) { value = val; } public void multiply(double val) { value *= ; } public void divide(double val) { /= val; } public void clear() { value = 0.0; } public double getValue() { return val; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
