Question: I need help with some Java homework. SOURCE CODE IS AT THE BOTTOM. This week we will write modify the memory calculator from 06. Sixth
I need help with some Java homework. SOURCE CODE IS AT THE BOTTOM.
This week we will write modify the memory calculator from 06. Sixth Assignment Memory Calculator to be able to save all of the calculations done to a file. There are multiple ways to do this, but I suggest creating an ArrayList of String objects. Each time the user performs an operation (add, subtract, multiply, divide, or clear), add a new String. For instance, if the current value is 6 and the user chooses to add 2, you would create a new String 6 + 2 = 8 and add that String to the ArrayList. You will also need to add a new Save item to the menu. When the user chooses this option, you should call a method that displays a JFileChooser dialog to the user, allow them to select where to save the data, and then write all of the strings from the ArrayList to that file. Be sure to handle exceptions gracefully.
________________________________________________________________________________________________________________________________________________
import java.util.*; public class MemoryCalculator {
double dv = 0.0; static Scanner sc = new Scanner(System.in); public static int displayMenu() { System.out.print("Menu 1. Add 2. Subtract 3. Multiply 4. Divide 5. Clear 6. Quit"); int choice = sc.nextInt(); return choice; } public void add(double operand2) { //Calculator ob = new Calculator(); dv=dv+operand2; System.out.println("The current value is "+dv); } public void subtract(double operand2) { //Calculator ob = new Calculator(); dv=dv-operand2; System.out.println("The current value is "+dv); } public void multiply(double operand2) { dv=dv*operand2; System.out.println("The current value is "+dv); } public void divide(double operand2) { dv=dv/operand2; System.out.println("The current value is "+dv); } public void clear() { dv=0.0; System.out.println("The current value is "+dv); } public void getCurrentValue() { System.out.println("The current value is "+dv); } public static void main(String[] args) { MemoryCalculator ob1 =new MemoryCalculator(); System.out.println("The current value is "+ob1.dv); System.out.println("What would you like to do?"); int input1 = displayMenu(); double op2; do { switch(input1) { case 1: System.out.println("What is the second number? "); op2 = sc.nextDouble(); ob1.add(op2); break; case 2: System.out.println("What is the second number? "); op2 = sc.nextDouble(); ob1.subtract(op2); break; case 3: System.out.println("What is the second number? "); op2 = sc.nextDouble(); ob1.multiply(op2); break; case 4: System.out.println("What is the second number? "); op2 = sc.nextDouble(); ob1.divide(op2); break; case 5: ob1.clear(); break; case 6: return; } System.out.println("What would you like to do?"); input1 = displayMenu(); }while(input1!=7);
}
}
? A save option has been added to the menu: 1 point
? The save option calls a method that displays a JFileChooser dialog and allows the user to select a file: 2 points
? The save method writes to the selected file: 1 point
? The information written to the selected file is correct: 2 points
? Exceptions are handled gracefully (i.e. nice error messages are displayed to the user rather than the stack trace): 1 point
? Your program compiles: 1point
? Your program runs: 1 point
? You follow standard coding conventions (e.g. variable names, indentation, comments, etc.): 1 point
? Note: If your program does not compile, you will receive a score of 0 on the entire assignment
? Note: If you program compiles but does not run, you will receive a score of 0 on the entire assignment
? Note: If your Eclipse project is not exported and uploaded to the eLearn drop box correctly, you will receive a score of 0 on the entire assignment
? Note: If you do not submit code that solves the problem for this particular assignment, you will not receive any points for the programs compiling, the programs running, or following standard coding conventions.
SAMPLE OF OUTPUT



The data in the file should look like this: Initial value is 0 0.0+5.0 5.0 5.0 3.0 2.e 2.05.0 10.0 10.0 0.0NaN Cleared
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
