HashTables, and Library Code
Concept of a Stack
GUI programming and events
Separation of GUI elements from underlying model of computation.
In a breadth first course, students should see a bit of assembler language in the first course. This module introduces a simple assembler like language and a simulator in which to execute the programs. The language is that of a simple stack machine. This module could be used to introduce stacks or (perhaps) GUI programming.
Featurs of the language that are required for this are:
Simple if and while statements
Simple Applet and GUI programming
Classes, methods, ...
The handouts below should be given to the students the class prior to the one in which it will be first discussed with instructions to read and understand it. Students should bring questions with them to the next class. The handout should be on paper (not electronic), so that they need to read it, not execute it. I would give this quite early in the course. They won't understand all of it, perhaps.
SourceCode (The SimpleCPU Class)
SourceCode( The required Prompter Class). The students can ignore the details of this class or not, as the instructor prefers.
Try it. (Or Right/Meta click to down load the html file. You need Sun's Java browser plugin to try it, however.)
Here is a simple object interaction diagram of the eight major objects in the system. See the Follow Up at the bottom for a bit of explanation about the roles of the objects. There is no inheritance visible here, except that SimpleCPU extends Applet.
Working in the classroom in teams of two, the student can be asked to (among other possibilities)
Students are given the code electronically at the end of class so that they can run and modify it.
They can then do any of the following
The Student Handouts are excerpted from some more extensive files. Instructors may obtain copies by contacting me.
This language can be extended a bit to show concurrency in action. It can also serve as the basis of the calculation part of a spreadsheet. In this latter case, programs of this form are stored in spreadsheet cells that are defined by a formula rather than a value. Each of these can serve as an additional course module.
In a course in which GUI elements are not introduced, the exercise can be modified to read and write standard input. It will then need to be an application, rather than an applet. In this case, the prompter is not needed.
Providing more of the flavor of assembler, including jump logic, requires that the program be saved, rather than just written as Java function calls. This is the subject of a later module, in which the fetch-increment-do cycle of a cpu is explored along with pseudo concurrency. The language is very nearly the same for this module.
The simpleCPUModel runs in its own thread so that the modal dialog box doesn't interfere with other operation of the applet. In this version, prompter is inefficient in that it creates a new dialog for each interaction. This should be fixed. (Perhaps by me, and perhaps by your students.)
There are eight main classes here, the SimpleCPUModel, Stack, and Hashtable (model), the Applet, Prompter, and Dialog (view) and two listeners (controller). There are also implicitly some other classes (Thread, Button, TextArea, TextField, Panel) that you might want to ignore. The prompter mediates between the model and the dialog.
This is a rather small Larger Than Life overall and is definitely a Toy Box. The in class exercise can be a Student Design Sprint. The Prompter class is both a Tool Box and a Fixer Upper. Some of the take home exercises are Fill in the Blanks. See http://csis.pace.edu/~bergin/PedPat1.2.html, and http://csis.pace.edu/~bergin/fivepedpat.html for further explanation of these patterns.