Ask Question
17 June, 12:49

The superclass Calculator contains: a protected double instance variable, accumulator, that contains the current value of the calculator. Write a public subclass CalculatorWithMemory, based on Calculator, a double instance variable, memory, initialized to 0 a method, save, that assigns the value of accumulator to memory a method, recall, that assigns the value of memory to accumulator a method, clearMemory, that assigns zero to memory a method, getMemory, that returns the value stored in memory

+1
Answers (1)
  1. 17 June, 16:17
    0
    The following program are written in JAVA Programming Language.

    //inherit the Calculator class

    public class CalculatorWithMemory extends Calculator {

    private double memory = 0.0; / /initialize double type variable

    public void save () { / /define function

    memory = accumulator;

    }

    public void recall () { / /define function

    accumulator = memory;

    }

    public void clearMemory () { / /define function

    memory = 0; / /initialize the value

    }

    public double getMemory () {

    return memory; / / return the value in "memory" variable

    }

    }

    Explanation:

    Here, we inherit the property of the "Calculator" class.

    Then, we define the private double type variable "memory" and assign value 0.0.

    Then we set the function "save () " inside it we assign the value of "memory" in "accumulator" and close the function.

    Then, we define the function "recall () " inside it we assign the value of "accumulator" in "memory" and close the function.

    Then we set the function "clearMemory () " inside it we assign "memory" to 0.

    After all, we set the double type function "getMemory () " inside we return the value of the "memory".
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “The superclass Calculator contains: a protected double instance variable, accumulator, that contains the current value of the calculator. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers