Business Programming

Course announcements for INFS1609 and INFS2609

Business Programming random header image

Tutorial – Week 10

Posted by on September 25th, 2011 · Labs

The following exercises are taken from chapter 10 of the textbook. Exercises 1 – 7 explore the simulation so that you become familiar with how it works and with the Java code. The most important exercises to complete for this week are exercises 8 and 9, so don’t spend too long on the earlier ones so that you can get onto creating your own class hierarchy.

Exercise 1 Open the foxes-and-rabbits-v1 project. Create a Simulator object using the constructor without parameters and you should see the initial state of the simulation. The more numerous rectangles represent the rabbits. Does the number of foxes change if you call the simulateOneStep just once?

Exercise 2 Does the number of foxes change on every step? What natural processes do you think we are modelling that cause the number of foxes to increase or decrease?

Exercise 3 Call the simulate method to run the simulation continuously for a significant number of steps, say 50 or 100. Do the numbers of foxes ad rabbits increase or decrease? You can use the runLongSimulation to see what happens over a long time.

Exercise 4 Use the reset method to create a new starting state and try running the simulation again. Is the simulation identical? If not, are there any similarities between runs?

Exercise 5 After having run the simulation for a while, reset it and also call the static reset method in the Randomizer class. Now run the first few steps again and you should see the original simulation repeated. Take a look at the code of the Randomizer class to see if you can work out why this might be. You might need to look at the API for the java.util. Random class to help you with this.

Exercise 6 Check that setting the userShared field on Randomizer to false breaks the repeatability of the simulations. Be sure to restore it to true afterwards because repeatability will be an important element in later testing.

Exercise 7 Experiment with different combinations of settings (breeding age, maximum age, breeding probability, litter size, etc) for foxes and rabbits. Do species always disappear completely in some configurations? Are there configurations that are stable?

Exercise 8 Identify the similarities and differences between the Fox and Rabbit classes. Make separate lists of the fields, methods and constructors and distinguish between the class variables (static fields) and instance variables.

Exercise 9 Create the Animal superclass in your version of the project. Ensure that the simulation works in a similar manner as before. You should be able to check this by having old and new versions of the project open side-by-side, making identical calls on Simulator objects in both, expecting identical outcomes.

 

No Comments so far ↓

Comments are closed.