001    /*
002     * Calculator Interface
003     *
004     * Developed for "Rethinking CS101", a project of Lynn Andrea Stein's.
005     * For more information, see <a href="http://www.cs101.org/">the
006     * CS101 homepage</a> or email <las@olin.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     * 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     *
024     * @see CalculatorGUI
025     */
026    public interface Calculator {
027        // buttonID constants.
028        // The numbers 0 through 9 should serve as buttonIDs for the respective buttons. 
029       /**
030        * No operation in progress.
031        */
032        public static final int NO_OP  = -1;
033    
034       /**
035        * Calculator division.
036        */
037        public static final int OP_DIV = 10;
038    
039       /**
040        * Calculator multiplication.
041        */
042        public static final int OP_MUL = 11;
043    
044       /**
045        * Calculator addition.
046        */
047        public static final int OP_ADD = 12;
048    
049       /**
050        * Calculator subtraction.
051        */
052        public static final int OP_SUB = 13;
053    
054       /**
055        * Calculator decimal point.
056        */
057        public static final int DOT    = 14;
058    
059       /**
060        * Calculator = button.
061        */
062        public static final int EQUALS = 15;
063    
064       /**
065        * Calculator clear button.
066        */
067        public static final int CLEAR  = 16;
068    
069       /**
070        * One more than the biggest button index.
071        */
072        public static final int LAST = 17; 
073    
074    
075       /**
076        * An array for the button's labels to deal with dispatch cleanly.
077        * You can use this to get the name of the button (i.e., a String).
078        */
079        public static String[] ButtonLabels = new String[Calculator.LAST];
080        
081       /**
082        * Get the next Button pressed.  The return value will be an int
083        * between 0 and 9 (if the button was a number) or one of the
084        * Calculator constants.
085        *
086        * @return the next button to be handled.
087        */
088        public int getButton();
089    
090       /**
091        * Get the text currently displayed on the Calculator.
092        *
093        * @return the text as a String.
094        */
095        public String getText();
096    
097       /**
098        * Set the text currently displayed on the Calculator.
099        *
100        * @param newText the text to be displayed.
101        */
102        public void setText( String newText );
103    
104    }
105    
106    /* Comments:
107     *
108     * History:
109     *     $Log: Calculator.java,v $
110     *     Revision 1.2  2004/03/26 21:04:11  gus
111     *     take ownership
112     *
113     *     Revision 1.1  2003/07/10 21:14:43  jon
114     *     Initial commit of spring03 calculator source.
115     *
116     *     Revision 1.1.1.1  2002/06/05 21:56:24  root
117     *     CS101 comes to Olin finally.
118     *
119     *     Revision 1.3  1997/10/05 21:11:19  shong
120     *     Updated for fall97, to Java 1.1
121     *     changed GUI, using 1.1 Event Model
122     *
123     *     Revision 1.2  1997/07/16 14:15:20  tparnell
124     *     *** empty log message ***
125     *
126     *     Revision 1.2  1996/10/04 16:20:20  las
127     *     Transformed Calculator into an application and made it a package.  See
128     *     STAFF_SETUP for which files are public.  To run, use Calculator.Main.
129     *
130     *     Specifics:
131     *         Added Main.java, which starts the calculator program (both
132     *     CalculatorGUI and ButtonHandler);
133     *         Made Calculator an interface;
134     *         Moved GUI implementation (previously in Calculator) to
135     *     CalculatorGUI.
136     *         Added clear button, which looks pretty gross right now.  (It can
137     *     be deleted in a single line, though.)
138     *
139     *     Revision 1.1.1.1  1996/07/18 17:26:12  sit
140     *     Import from summer 6.80s web tree
141     *
142     *
143     */
144    
145