title: java calculator- clearing accumulator
body: <p>So far in my calculator, I can input the problem and get the correct solution. My issue is when I click the clear button (to clear the accumulator and start a new problem) it sets the text box blank but keeps the stored values. I tried creating a reset method in my accumulator class but so far I am stuck. Any tips??</p>
  
  <pre><code>import acm.program.*;
  import javax.swing.*;
  import java.awt.*;    // for graphics 
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import acm.gui.*;
  public class Calculator extends DialogProgram implements ActionListener{ 
  
  
  JButton b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,bm,bd,ba,bs,bdec,bc,bequ;
  DoubleField screen = new DoubleField();
  
  JPanel P,P1,P2;
  Accumulator acc = new Accumulator();
  double result;
  
  public void init() {
  
  
  //create a panel 
  
  
  JPanel P= new JPanel();     // main panel 
  
  JPanel P1= new JPanel();    // panel for buttons 
  
  JPanel P2= new JPanel();    // panel for screen
  
  // adding panel to dialog box
  
  add(P);        // main panel 
  P.add(P2);     // adding screen
  P.add(P1);     // adding panel of buttons 
  
  // set panel color 
  P.setBackground(Color.yellow);                 
  
  
  // grid layout for buttons 
  
  P1.setLayout(new GridLayout(5,4,4,4));           // layout for button panel 
  P.setLayout(new GridLayout(2,1));                // layout for main panel 
  
  // create screen 
  //screen = new DoubleField();                      // creating screen 
  screen.setPreferredSize(new Dimension(200,40));  // setting screen size 
  screen.setEditable(false);                       // screen can not be edited 
  
  // integer buttons 
  b0 = new JButton("0");
  b1 = new JButton("1");
  b2 = new JButton("2");
  b3 = new JButton("3");
  b4 = new JButton("4");
  b5 = new JButton("5");
  b6 = new JButton("6");
  b7 = new JButton("7");
  b8 = new JButton("8");
  b9 = new JButton("9");
  
  // operator buttons 
  bm = new JButton("*");
  bd= new  JButton("/");
  ba = new JButton("+"); 
  bs = new JButton("-");
  
  // decimal button 
  bdec = new JButton(".");
  
  // clear button
  bc = new JButton("Clr");
  
  // equal button
  bequ = new JButton("=");
  
  // adding buttons to panel 
  P2.add(screen);
  P1.add(b7);
  P1.add(b8);
  P1.add(b9);
  P1.add(bm);
  P1.add(b4);
  P1.add(b5);
  P1.add(b6);
  P1.add(bd);
  P1.add(b1);
  P1.add(b2);
  P1.add(b3);
  P1.add(ba);
  P1.add(bc);
  P1.add(b0);
  P1.add(bdec);
  P1.add(bs);
  P1.add(bequ);
  
  // adding action listeners 
   bm.addActionListener(this); 
   bd.addActionListener(this); 
   bs.addActionListener(this); 
   ba.addActionListener(this);
   b9.addActionListener(this); 
   b8.addActionListener(this); 
   b7.addActionListener(this); 
   b6.addActionListener(this); 
   b5.addActionListener(this); 
   b4.addActionListener(this); 
   b3.addActionListener(this); 
   b2.addActionListener(this); 
   b1.addActionListener(this); 
   b0.addActionListener(this); 
   bdec.addActionListener(this); 
   bc.addActionListener(this); 
   bequ.addActionListener(this);
  
  
  
   //addActionListeners();
  
  
  } // close 
  
  //public static void main(String[] args) {
  //  new Calculator().start(args);   
  
  
  
  //}
  
  
  public void actionPerformed (ActionEvent e) {
       String clicked =e.getActionCommand();
       if (clicked.equals("1")) {
           screen.setText(screen.getText()+clicked);
       }  
       if (clicked.equals("2")) {
           screen.setText(screen.getText()+clicked);
       }
       if (clicked.equals("3")) {
           screen.setText(screen.getText()+clicked);
       }
       if (clicked.equals("4")) {
           screen.setText(screen.getText()+clicked);
       }
       if (clicked.equals("5")) {
           screen.setText(screen.getText()+clicked);
       }
       if (clicked.equals("6")) {
           screen.setText(screen.getText()+clicked);
       }
       if (clicked.equals("7")) {
           screen.setText(screen.getText()+clicked);
       }
       if (clicked.equals("8")) {
           screen.setText(screen.getText()+clicked);
       }
       if (clicked.equals("9")) {
           screen.setText(screen.getText()+clicked);
       }
       if (clicked.equals("0")) {
           screen.setText(screen.getText()+clicked);
       }
       if (clicked.equals("*")) {
          // screen.setText(screen.getText()+clicked);
           acc.calculate(screen.getValue(), "*");
           screen.setText("");
       }
       if (clicked.equals("/")) {
          // screen.setText(screen.getText()+clicked);
           acc.calculate(screen.getValue(), "/");
           screen.setText("");
       }     
       if (clicked.equals("+")) {
          // screen.setText(screen.getText()+clicked);
           acc.calculate(screen.getValue(), "+");
           screen.setText("");
       } 
       if (clicked.equals("-")) {
           acc.calculate(screen.getValue(), "-");
           screen.setText("");
       } 
       if (clicked.equals(".")) {
           screen.setText(screen.getText()+clicked);
       }
       if (clicked.equals("Clr")) {
           acc.reset();
           screen.setText("");
  
       } 
  
       if (clicked.equals("=")) {
          // screen.setText("");
           acc.calculate(screen.getValue(), "=");
           screen.setValue(acc.getValue());
  
          // screen.setText(result);
  
       } 
  
  
  
  }/*action Performed*/
  
  
  public class Accumulator{
      double valueSoFar;
      String currentOperator;
  
      Accumulator(){
          valueSoFar=0.0;
          currentOperator="C";
  
      }
      /*constructor*/
  
      public void calculate(double numberOnDisplay, String nextOperator) {
          if (currentOperator.contentEquals("+")) {
              valueSoFar= valueSoFar + numberOnDisplay;
  
          }
          if (currentOperator.contentEquals("-")) {
              valueSoFar= valueSoFar - numberOnDisplay;
          }
          if (currentOperator.contentEquals("*")) {
              valueSoFar= valueSoFar * numberOnDisplay;
          }
          if (currentOperator.contentEquals("/")) {
              valueSoFar= valueSoFar / numberOnDisplay;
          }
          if (currentOperator.equals("C")) {
              valueSoFar = numberOnDisplay;
          //  currentOperator = nextOperator;
  
          }
          //  getValue();
  
          //}
  
  
  
  
          currentOperator = nextOperator;
  
      }/*calculate*/
  
      public double getValue() {
          return valueSoFar;
          }    /*getValue*/
  
      public double reset() {
  
          return valueSoFar;
      }
  
  }/*Accumulator*/
  
  
  } /*Class*/
  </code></pre>