Question: JAVA Assignment Scientific Memory Calculator In this assignment, you will write a subclass of the MemoryCalc class from 06. Sixth Assignment Memory Calculator. This new
JAVA Assignment Scientific Memory Calculator
In this assignment, you will write a subclass of the MemoryCalc class from 06. Sixth Assignment Memory Calculator. This new calculator, called ScientificMemCalc, should be able to do everything that the MemoryCalc could do, plus raise the current value to a power and compute the natural logarithm of the current value. This is a fairly realistic assignment often when you are working for a company, you will be asked to make minor extensions to existing code. You will need to override the displayMenu method to add the new options. Be sure to only add code to the ScientificMemCalc class if it is necessary leverage the code from the base MemoryCalc class whenever possible. Use the power of inheritance to do this rather than cutting and pasting or otherwise duplicating the code. Finally, write a new class called ScientificCalcDriver that shows the functionality of your new class. This will be very similar to the CalcDriver class contained in the assignment9.jar file.
Sample output:
The current value is 0.0
Menu
1. Add
2. Subtract
3. Multiply
4. Divide
5. Power
6. Logarithm
7. Clear
8. Quit
What would you like to do? 1
What is the second number? 20
The current value is 20.0
Menu
1. Add
2. Subtract
3. Multiply
4. Divide
5. Power
6. Logarithm
7. Clear
8. Quit
What would you like to do? 2
What is the second number? 10
The current value is 10.0
Menu
1. Add
2. Subtract
3. Multiply
4. Divide
5. Power
6. Logarithm
7. Clear
8. Quit
What would you like to do? 3
What is the second number? 3
The current value is 30.0
Menu
1. Add
2. Subtract
3. Multiply
4. Divide
5. Power
6. Logarithm
7. Clear
8. Quit
What would you like to do? 4
What is the second number? 6
The current value is 5.0
Menu
1. Add
2. Subtract
3. Multiply
4. Divide
5. Power
6. Logarithm
7. Clear
8. Quit
What would you like to do? 5
What is the second number? 2
The current value is 25.0
Menu
1. Add
2. Subtract
3. Multiply
4. Divide
5. Power
6. Logarithm
7. Clear
8. Quit
What would you like to do?
6 The current value is 3.2188758248682006
Menu
1. Add
2. Subtract
3. Multiply
4. Divide
5. Power
6. Logarithm
7. Clear
8. Quit
What would you like to do? 7
The current value is 0.0
Menu
1. Add
2. Subtract
3. Multiply
4. Divide
5. Power
6. Logarithm
7. Clear
8. Quit
What would you like to do? 8
Goodbye!
I have this code Below that nneds to be modified:
package memoryCalculator;
import java.util.Scanner;
public class MemoryCalculator {
static Scanner keybd = new Scanner(System.in); private double currentValue = 0;
public static int displayMenu() { System.out.print("Menu 1. Add " + "2. Subtract " + "3. Multiply " + "4. Divide " + "5. Clear " + "6. Quit " + "What would you like to do? "); return Integer.parseInt(keybd.nextLine()); }
public static double getOperand(String prompt) { System.out.print(prompt + " "); return Double.parseDouble(keybd.nextLine()); }
public double getCurrentValue() { return currentValue; }
public void add(double operand2) { currentValue += operand2; }
public void subtract(double operand2) { currentValue -= operand2; }
public void multiply(double operand2) { currentValue *= operand2; }
public void divide(double operand2) { if (operand2 == 0) { currentValue = Double.NaN; return; } currentValue /= operand2; }
public void clear() { currentValue = 0; }
public static void main(String[] args) { MemoryCalculator c = new MemoryCalculator();
System.out.println("The current value is " + c.getCurrentValue()); int choice = displayMenu(); while (choice != 6) { switch (choice) { case 1: c.add(getOperand("What is the second number?")); System.out.println("The current value is " + c.getCurrentValue()); break; case 2: c.subtract(getOperand("What is the second number?")); System.out.println("The current value is " + c.getCurrentValue()); break; case 3: c.multiply(getOperand("What is the second number?")); System.out.println("The current value is " + c.getCurrentValue()); break; case 4: c.divide(getOperand("What is the second number?")); System.out.println("The current value is " + c.getCurrentValue()); break; case 5: c.clear(); System.out.println("The current value is " + c.getCurrentValue()); break; default: System.out.println("Invalid Choice!"); break; }
System.out.println(); choice = displayMenu(); }
System.out.println("Good Bye!"); }
} // end main
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
