| Homework 5DetailsFor this assignment you will improve the Foxes And Rabbits simulation from Homework 4 by adding more buttons. The application should have the following things.
- One button that will run 1 step of the simulation.
- One button that will run 100 steps of the simulation.
- One button that will run the long simulation.
- One button and associated text field to allow the user to specify
the number of steps to run.
- One button that will reset the simulation.
- A JMenuBar which contains
- "File->Exit" which exits the application
- "Help->About" which gives information about who wrote the application, etc.
(use the JOptionPane.showMessageDialog method for this).
To keep the simulation from being buggy, you should disable all of the buttons while the simulation is running.
Note: You can't just disable them at the beginning of the listener and re-enable them at the end because the simulation is run in a different thread and the listener will return almost immediately. But you can disable/re-enable them at the beginning and end of the run method in the thread. However, if you want to keep Reset enabled during a run so that it will stop the current simulation and reset it, you will also need a boolean field and related code in several places to deal with this.
The application should quit properly when the "X" in the upper right
corner is clicked. This is properly implemented in my version of the code,
but if you move the main JFrame somewhere else, you will have to make sure
you copy the WindowListener code.
You should continue with your code from Homework 4.
Note: In this version Simulator and SimulatorView have been slightly modified to make it a bit easier (the version in the book was not designed to make adding buttons easy). I should also point out that this code is based on an earlier addition of the textbook so the code may have other differences.
For more of a challenge (and bonus points), do any of the following:
- Allow the user to select parameters of the simulation like board width and height,
and creation probabilities. When the user hits reset, the newly generated board will
be based on these parameters.
- Allow the user to select the stats for each creature,
including max age, max litter size, etc. This will require modifying the code for
Rabbit and Fox, among other things.
- Allow the user to click on the squares to place rabbits, foxes, etc. One way to
do this is to have each click rotate around the options (rabbit->fox->hunter->empty->rabbit...).
- Deal with potential errors with what the user puts in the text field.
Grading
Criteria | Points |
Correctness | 10 |
Design | 10 |
Style/Documentation | 5 |
GUI/Interface | 5 |
Total | 30 |
Bonus | 5 |
Handing it in
- In Eclipse, right-click on your Foxes and Rabbits 3 project and select New-->File.
- Enter MyGrade.txt for the File name and click Finish.
- Double-click on the MyGrade.txt file that you just created (It should be displayed as part of your project--probably the last thing listed). It should bring the file up in Eclipse in a text editor.
- In MyGrade.txt create 2 charts similar to the one from HW 3 but with the criteria for HW 4 and HW 5 (in that order). The easiest way to do this is cut and paste from the homework pages (it will convert the tables to text).
- Fill in the charts you just created with your self-evaluation for each project. Make sure you provide totals (out of 30) for each project.
- Provide a justification for your self-evaluation. This should be more than one or two sentences but less than half a page.
- In Windows Explorer, right click on the Foxes and Rabbits 3 folder and select Send to-->Compressed (zipped) folder.
- Name the zipfile whatever you wish.
- Use Webhandin with assignment 235-HW5 to submit the zipfile you just created.
|