Ask Question
28 June, 08:47

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. 28 June, 12:25
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers