Calculator Class
In the file Calculator.java, write a class called Calculator that emulates basic functions of a calculator: add, subtract, multiply, divide, and clear. The class has one private member field called value for the calculator's current value. Implement the following Constructor and instance methods as listed below:
Given two double input values num1 and num2, the program outputs the following values:
Ex: If the input is:
the output is:
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 valueSystem.out.println(calc.getValue());// 2. The value after adding num1calc.add(num1);System.out.println(calc.getValue());// 3. The value after multiplying by 3calc.multiply(3);System.out.println(calc.getValue());// 4. The value after subtracting num2calc.subtract(num2);System.out.println(calc.getValue());// 5. The value after dividing by 2calc.divide(2);System.out.println(calc.getValue());// 6. The value after calling the clear() methodcalc.clear();System.out.println(calc.getValue());}}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here