CS151 Final
Exam F
09
For this exam I want you to create an Eclipse project. The name of the project should be your last name (abbreviations are okay). The project will contain one package for each problem. The first problem requires the application framework discussed in class so you may also want to include the framework package, too. Note the folder where the project is stored in your file system (look under the Project/Properties/Resources menu). At the end of the exam, you will turn this folder into a zip file and mail it as an attachment to jon.pearce@sjsu.edu.
Remember, you can get partial credit even if your programs don't run.
Clicking the "next" button on the Fibonacci Generator's GUI displays the next two Fibonacci numbers in the famous Fibonacci sequence.
Here are a few successive screen shots:
The File menu contains the items: New, Save, SaveAs, Open, and Exit. The Edit menu contains the items: Undo and Redo.
Implement the Fibonacci Generator by customizing the Application Framework developed in class. (Recall that the application framework employs the following patterns: Publisher-Subscriber, Command Processor, and Memento. Your customization is required to complete these patterns.) The next three steps will guide you through this process.
Finish the implementation of the model extension:
Recall, the Fibonacci sequence starts out:
0, 1, 1, 2, 3, 5, 8, 13, ...
If fib1 and fib2 are consecutive numbers in this sequence, then the next two consecutive numbers will be fib2 and fib1 + fib2.
Finish the implementation of the Command extension:
Finish the implementation of the View extension:
Hints: The button label, "next", is the action command the button generates when clicked. Recall that the edit menu controller (called ec in the View class) will pass this string to the makeCommand override in FibView. This method returns a new instance of NextFibCommand, which ec asks the command processor to execute.
Should markets be regulated or free? Create a simulation to determine the answer. Use the Master-Slave pattern and the Strategy pattern.
A market consists of N participants. Initially, each participant has $100. Each participant randomly selects another participant and does a deal. Independently, the participants decide to cheat or not. If both cheat, neither increases their wealth. If one cheats and the other doesn't, then the cheater's wealth is incremented by $50 and the other's wealth is decremented by $10. If neither cheats, then the wealth of each is incremented by $30. A participant repeats this task K times or until they are out of money.
Among the N participants, the first N1 always cheat, the second N2 are impulsives who cheat randomly. The rest are honest.
At the end of the simulation, each participant is printed along with his wealth. How do the honest participants do against the impulsives and the cheaters?
Hints:
I have provided sketches of Market and Participant, which you can complete:
At the end of a deal the participant who initiated the deal should update the wealth of himself and the other participant. Be careful. While a participant only initiates one deal at a time, he can be simultaneously participating in multiple deals initiated by other participants, and so several participants can be trying to update his wealth at the same time.