Can anyone help me modify my code in Java?
<p>Okay to make this clearer this is what i need done to my entire program. I need main to restore any calculators that are in the file "calc.bak" before presenting the user with a menu and main should save all calculators that exist in that same file (overwrite as appropriate) just before exiting. I also need to give the user the option to create a brand new calculator, name it, and add a function to it from an already existing collection (which are my Add, multiply, and divide). I also need the user to create their own function by designing and naming a combination of any pair of functions. The ouput of the first function would necessarily be input to the second function. For example, the user can create a new function called "addmult" that calls the add function (which prompts for two numbers and adds them) and establishes the sum as one of the operands for the multiply function (which would have to prompt for its second operand).  </p>

<p>The sample out put should look like this:
Welcome to the Calculator Configurator</p>

<ol>
<li><p>restore a calculator from a file</p></li>
<li><p>create a calculator from scratch</p></li>
<li><p>let me create a calculator you can use</p></li>
</ol>

<p>2</p>

<p>OK. so you want to create one yourself.</p>

<p>What is the name of your calculator? Fred</p>

<p>Indicate which functions from our stock you'd like to add to your calculator (enter 0 to quit this menu):</p>

<p>Add(1)</p>

<p>Multiply(2)</p>

<p>Divide(3)</p>

<p>Pair of functions(4)</p>

<p>input (2)</p>

<p>Indicate which functions from our stock you'd like to add to your calculator (enter 0 to quit this menu):</p>

<p>Add</p>

<p>Multiply</p>

<p>Divide</p>

<p>Pair of functions</p>

<p>1
Indicate which functions from our stock you'd like to add to your calculator (enter 0 to quit this menu):
 Add</p>

<p>Multiply</p>

<p>Divide</p>

<p>Pair of functions</p>

<p>4</p>

<p>Provide a name for this pair: </p>

<p>BothAddAndMult</p>

<p>Provide a description for this pair: </p>

<p>multiplies and then adds</p>

<p>Which function should be first?</p>

<p>Multiply(0)</p>

<p>Add(1)</p>

<p>0</p>

<p>Which function should be first?</p>

<p>Multiply</p>

<p>Add</p>

<p>1</p>

<p>Indicate which functions from our stock you'd like to add to your calculator (enter 0 to quit this menu):</p>

<p>Add</p>

<p>Multiply</p>

<p>Divide</p>

<p>Pair of functions</p>

<p>4</p>

<p>Provide a name for this pair: </p>

<p>MultAfter</p>

<p>Provide a description for this pair: multiplies last after a multiply and add</p>

<p>Which function should be first?</p>

<p>Multiply</p>

<p>Add</p>

<p>BothAddAndMult</p>

<p>2</p>

<p>Which function should be first?</p>

<p>Multiply</p>

<p>Add</p>

<p>BothAddAndMult</p>

<p>Indicate which functions from our stock you'd like to add to your calculator (enter 0 to quit this menu):</p>

<p>Add</p>

<p>Multiply</p>

<p>Divide</p>

<p>Pair of functions</p>

<p>0</p>

<p>I am a calculator named Fred</p>

<ol>
<li><p>quit</p></li>
<li><p>clear memory</p></li>
<li><p>multiply two numbers</p></li>
<li><p>add two numbers</p></li>
<li><p>multiplies and then adds</p></li>
<li><p>multiplies last after a multiply and add</p></li>
</ol>

<p>Can someone help me reach this output?</p>

<p>Here is my code so far</p>

<h3>CalcConfig.java</h3>

<pre><code>import java.util.Scanner;

// program to model a configurable calculator
public class CalcConfig {
 public static void main(String [] args)
 {
   System.out.println("Welcome to the Calculator Configurator");
   Scanner kbd = new Scanner(System.in);
   CalcFunction [] funs = {
     new Add(kbd, "add two numbers"),
     new Multiply(kbd, "Multiply two numbers"),
     new Divide(kbd, "divide two numbers")};
   Calculator calc = new Calculator(funs);
   calc.go(kbd);

}
}
</code></pre>

<h3>Calculator.java</h3>

<pre><code>//my Calculator class

import java.util.Scanner;

// models a configurable calcuator
public class Calculator {
   private CalcFunction [] functions;
   private double memory = 0;
   private boolean clear = true;

public Calculator(CalcFunction [] functions)
{
   this.functions = functions;
}

public void go(Scanner kbd)
{
   int choice = 0;
   do
   {
      System.out.println(this);
      choice = kbd.nextInt();
      if (choice == 0) return; // choice is to quit
      if (choice == 1)
      {
         clear = true;
         continue;
      }
      if (choice &lt; 0 || choice &gt;= 5)
       {
          System.out.println("error");
          continue;
       }
      if (!clear)
       {
          System.out.print("use memory [" + memory + "] (y or n)? ");
          String ans = kbd.next();
          if (ans.equals("n")) clear = true;
       }
      if (clear)
       memory = functions[choice-2].doit();
     else
       memory = functions[choice-2].doit(memory);
     clear = false;
     System.out.println(memory);
} while(choice != 0);
}

public String toString()
{
    String out = "0. quit\n1. clear memory\n";
    for (int i=0; i&lt;functions.length; i++)
    out += (i+2) + ". " + functions[i] + "\n";
    return out;
}
}
</code></pre>

<h3>CalcFunction.java</h3>

<pre><code>//my CalcFunction class
import java.util.Scanner;

// generic class to model a function in a calculator
public abstract class CalcFunction {
       private Scanner kbd;
       private String description;

public CalcFunction(Scanner kbd, String description)
{
       this.kbd = kbd;
       this.description = description;
}

public abstract double doit();
public abstract double doit(double memory);

// get a string from the user
protected String getString(String prompt)
{
     System.out.print(prompt);
     return kbd.next();
}
// get a number from the user
protected double getNum(String prompt)
{
     System.out.print(prompt);
     while(!kbd.hasNextDouble())
     {
         System.out.print("Invalid: need a number: ");
         kbd.next(); // discard invalid input
     }
     return kbd.nextDouble();
}

public String toString()
{
  return description;
}
}
</code></pre>

<h3>Add.java</h3>

<pre><code>//just one of my functions(Add)
import java.util.Scanner;

// class to encapsulate adding two numbers
public class Add extends CalcFunction {
public Add(Scanner kbd, String description)
{
     super(kbd, description);
}

public double doit()
{
    double n1 = this.getNum("Enter a number: ");
    return this.doit(n1);
}

public double doit(double first)
{
    double n2 = this.getNum("Enter a second number: ");
    double answer = first + n2;
    return answer;
}
}
</code></pre>

<p>Please help if you can.  Thanks!</p>
