001    /*
002     * Calculator Interface
003     *
004     * Developed for "Rethinking CS101", a project of Lynn Andrea Stein's AP Group.
005     * For more information, see <a href="http://www.ai.mit.edu/projects/cs101/">the
006     * CS101 homepage</a> or email <las@ai.mit.edu>.
007     *
008     * Copyright (C) 1996 Massachusetts Institute of Technology.
009     * Please do not redistribute without obtaining permission.
010     */
011    package calculator;
012    
013    /**
014     * This is the interface for a basic four-function calculator, as seen
015     * from the perspective of its logic.
016     *
017     * <P>This interface defines an enumerated type, buttonIDs (including
018     * 0...9, which represent themselves), an array of ButtonLabels
019     * suitable for displaying on the GUI, and the three access functions
020     * by which the logic can manipulate the Calculator: getButton,
021     * getText, and setText.
022     *
023     * <P>Copyright (c) 1998 Massachusetts Institute of Technology
024     *
025     * @author:  Emil Sit, sit@mit.edu
026     * @author:  Lynn Andrea Stein, las@ai.mit.edu
027     * @version: $Id: Calculator.java,v 1.1.1.1 2002/06/05 21:56:34 root Exp $
028     *
029     * @see CalculatorGUI
030     */
031    public interface Calculator {
032      // buttonID constants.
033      // The numbers 0 through 9 should serve as buttonIDs for the respective buttons. 
034      /**
035       * No operation in progress.
036       */
037      public static final int NO_OP  = -1;
038    
039      /**
040       * Calculator division.
041       */
042      public static final int OP_DIV = 10;
043    
044      /**
045       * Calculator multiplication.
046       */
047      public static final int OP_MUL = 11;
048    
049      /**
050       * Calculator addition.
051       */
052      public static final int OP_ADD = 12;
053    
054      /**
055       * Calculator subtraction.
056       */
057      public static final int OP_SUB = 13;
058    
059      /**
060       * Calculator decimal point.
061       */
062      public static final int DOT    = 14;
063    
064      /**
065       * Calculator = button.
066       */
067      public static final int EQUALS = 15;
068    
069      /**
070       * Calculator clear button.
071       */
072      public static final int CLEAR  = 16;
073    
074      /**
075       * One more than the biggest button index.
076       */
077      public static final int LAST = 17; 
078    
079    
080      /**
081       * An array for the button's labels to deal with dispatch cleanly.
082       * You can use this to get the name of the button (i.e., a String).
083       */
084      public static String[] ButtonLabels = new String[Calculator.LAST];
085        
086      /**
087       * Get the next Button pressed.  The return value will be an int
088       * between 0 and 9 (if the button was a number) or one of the
089       * Calculator constants.
090       *
091       * @return the next button to be handled.
092       */
093      public int getButton();
094    
095      /**
096       * Get the label for the given Button ID.  The argument 
097       * should be an int between 0 and 9 (if the button was 
098       * a number) or one of the Calculator constants, 
099       * otherwise the empty string ("") will be returned.
100       *
101       * @return the button label as a String.
102       */
103      public String getButtonLabel(int buttonID);
104    
105      /**
106       * Get the text currently displayed on the Calculator.
107       *
108       * @return the text as a String.
109       */
110      public String getText();
111    
112      /**
113       * Set the text currently displayed on the Calculator.
114       *
115       * @param newText the text to be displayed.
116       */
117      public void setText( String newText );
118    
119    }
120    
121    /* Comments:
122     *
123     * History:
124     *     $Log: Calculator.java,v $
125     *     Revision 1.1.1.1  2002/06/05 21:56:34  root
126     *     CS101 comes to Olin finally.
127     *
128     *     Revision 1.1  1999/10/08 15:09:23  las
129     *     This pset replaces the old Calculator pset.  However, not everything
130     *     has been transferred.  At the moment, it's just java, doc, and index.
131     *     The rest are still in the repository under Calculator-Old.
132     *
133     *     Revision 1.4  1998/07/24 16:37:14  tparnell
134     *     Placate new javadoc behavior
135     *
136     *     Revision 1.3  1998/07/06 19:08:52  tparnell
137     *     *** empty log message ***
138     *
139     *     Revision 1.2  1998/06/05 05:19:26  craigh
140     *     added getButtonLabel() to Calculator interface.  Implemented the
141     *     method in CalculatorGUI, and made use of it in ButtonHandler.
142     *
143     *     Revision 1.1  1998/02/26 17:25:44  tparnell
144     *     Reconstruction from hard drive failure.  Everything appears intact.
145     *
146     *     Revision 1.3  1997/10/05 21:11:19  shong
147     *     Updated for fall97, to Java 1.1
148     *     changed GUI, using 1.1 Event Model
149     *
150     *     Revision 1.2  1997/07/16 14:15:20  tparnell
151     *     *** empty log message ***
152     *
153     *     Revision 1.2  1996/10/04 16:20:20  las
154     *     Transformed Calculator into an application and made it a package.  See
155     *     STAFF_SETUP for which files are public.  To run, use Calculator.Main.
156     *
157     *     Specifics:
158     *         Added Main.java, which starts the calculator program (both
159     *     CalculatorGUI and ButtonHandler);
160     *         Made Calculator an interface;
161     *         Moved GUI implementation (previously in Calculator) to
162     *     CalculatorGUI.
163     *         Added clear button, which looks pretty gross right now.  (It can
164     *     be deleted in a single line, though.)
165     *
166     *     Revision 1.1.1.1  1996/07/18 17:26:12  sit
167     *     Import from summer 6.80s web tree
168     *
169     *
170     */
171