Defining the class
Your STCalculator class is now created, but as you can see in the text pane, there are no variables. The class STCalculator will need variables to keep track of its state. You define class and instance variables in the text pane displayed. We'll also define temporary variables later in the methods that need them.
Now is the time to take your best guess at which class-wide variables you will need. Our calculator object will be created as an instance of the class STCalculator, so the calculator state variables will be instance variables.
1. Edit the text pane to add the instance variables textWidget, lastValue, operation, and state. To add the variables, position the insert cursor between the two single quotes following instanceVariableNames:.
The variable textWidget holds the numeric display widget. The variable lastValue is a number memory for the calculator. The variable operation denotes which function has been selected. The variable state lets the calculator remember whether it is in function mode or equals mode.
2. The class will use constants from the CwConstants pool dictionary. Thus, the class definition needs to have a reference to it. Add CwConstants between the single quotes following poolDictionaries:.
3. Save the contents of the text pane. Recall the different ways you can save text:
a. Press Ctrl+S.
b. With the mouse pointer over the text area, press the second mouse button to activate the pop-up menu. Select Save.
c. Select Save from the File menu.
Your class definition should look like the following:
Last modified date: 03/26/2020