Assignment 0: Robotic Squirrels
University of Toronto, St. George Campus
Due May 31st, 2001, at the beginning of your tutorial.
Worth 4% of Grade
Introduction
The year is 3001. The place is Mars. And it’s hazelnut harvesting time.
Hazelnuts are the single most important crop for the inhabitants of Mars. They eat hazelnuts in soups, sauces and soufflés. They use hazelnut fibres to make clothing and furniture. They carve souvenirs out of hazelnut peels and use them as fuel.
To make the hazelnut harvesting process more efficient, the Martian engineers have invented two kinds of Robotic Squirrels : the cheaper SquirrelSimplex model and the more advanced SquirrelSapiens model. These two types of Robotic Squirrel travel through the Martian hazelnut forests, collect hazelnuts and store them in their reservoirs. Human hazelnut collectors can then extract the hazelnuts from the Robotic Squirrels.
Summary
Your task for this assignment will be to write part of a java program that models the two different types of Robotic Squirrels. Your program will be made up of three java files that each store one class. The AssignmentZero.java file contains the main method that creates Robotic Squirrel objects and calls methods on these objects to perform various tasks. The SquirrelSimplex.java and SquirrelSapiens.java files contain classes that model two different types of Robotic Squirrels.
Create a CodeWarrior project named AssignmentZero which contains all three files. You should download these files from the web, rather than typing them in again. Then you must complete the missing parts of these classes.
AssignmentZero class
This class contains the main method of the program, where execution commences. Notice that the body of the main method in AssignmentZero contains only comment statements. After each comment, you should add one or more statements, as the comment indicates.
The first part of the code in this class instantiates a SquirrelSimplex object and calls some methods on it, and the second part of this class instantiates a SquirrelSapiens object and calls some methods on it.
SquirrelSimplex class
This class models the cheap kind of Robotic Squirrel. It has an instance variable called 'numHazelnuts' which stores the number of hazelnuts currently existing in the Squirrel reservoir. It provides methods for: extracting hazelnuts (a specified number of them) from the reservoir; picking exactly one hazelnut off a tree and adding it to the reservoir; and returning the current number of hazelnuts in the Squirrel reservoir. Your task is to fill in the missing method bodies and prototypes. You will not need to write any additional methods.
SquirrelSapiens class
This class models the more complex kind of Robotic Squirrel. As well as having the 'numHazelnuts' instance variable to store the number of hazelnuts currently in the reservoir, it has a variable that stores the price of one hazelnut (in Martian cents), and the total value of the hazelnuts (in Martian cents) which that particular Robotic Squirrel is carrying.
Notice that all instance variables are given starting values of zero when an object is first instantiated from the class. This is actually the default behaviour; java would initialize the int variables to 0 anyway if we had not done it explicitly (the "default", or non-explicit, initialization is what happened in the SquirrelSimplex class).
As with the SquirrelSimplex class, the SquirrelSapiens class has a method that extracts hazelnuts from the machine. It has a more advanced method to pick hazelnuts off the tree and add them to the reservoir; this allows the SquirrelSapiens to pick any number of hazelnuts with a single call to the method. It always keeps track of the value of the hazelnuts in the reservoir (based on the number of hazelnuts and the value of one hazelnut). It also has a method that prints out the contents of its three instance variables. Again, there is no need to write additional methods.
What to Hand In
For this assignment, you must:
The pages in your assignment should be stapled together, in the following order: AssignmentZero, SquirrelSimplex, SquirrelSapiens, and your output. Put your printouts and your floppy diskette into an 8.5x11" unsealed envelope, and give it to your TA at the beginning of your tutorial. You must attach the cover page to the outside of the envelope.
Late assignments must be left in the CSC108 late drop box (just outside room SF2305A). The penalties stated in the course outline will be applied to late assignments.