Answered! The superclass Calculator contains: a (protected) double instance variable , accumulator, that contains the current value of the calculator….

The superclass Calculator contains: a (protected) double instance variable , accumulator, that contains the current value of the calculator.

Write a subclass, CalculatorWithMemory, that contains: 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.

Expert Answer

 you can write it in two different ways i.e you can write the subclass CalculatorWithMemory and no need to write superclass Calculator i.e shown below

public class CalculatorWithMemory extends Calculator

{

private double memory = 0 ; // the memory is initialized to zero

public void save ( )

{

memory = accumulator ; // the value of accumulator assigned to memory

}

public void recall ( )

{

accumulator = memory ; // the value of memory again assigned to accumulator

}

public void clearMemory ( )

{

memory = 0 ; // here zero value assigned to memory

}

public double getMemory ( )

{

return memory ;   // it returns the value stored in the memory

}

}

Still stressed from student homework?
Get quality assistance from academic writers!