Due: Friday, November 5th, 2010 9:40am
Although you implement this assignment in Java with Eclipse, handin your work using DrRacket. The handin server will not try to run any tests. The handin server will call your submitted file hw.java; unfortuately, however, the file will be saved in DrRacket’s non-text format.
Use the subset of Java that we have covered in class. In particular, use the = assignment operator only in constructors.
The relevant properties of a lion are, in order
Here is an initial class definition:
class Lion { int teeth; String ate; Lion(int teeth, String ate) { this.teeth = teeth; this.ate = ate; } }
Implement the Lion method moreScary, which produces a lion with two additional teeth (but the same stomach contents).
Design a representation for tigers, where the relevant properties of a tiger are
Use Tiger as the name of your class, and put the constructor arguments in the above order.
Implement the Tiger method moreScary, which produces a tiger (with the same fur pattern and stomach contents) whose claws are one centimeter longer.
Design a representation for bears, where the relevant properties of a bear are
Use Bear as the name of your class, and put the constructor arguments in the above order.
Implement the Bear method moreScary, which produces a bear (with the same fur color) that hasn’t eaten recently.
Define the interface IOzAnimal and adjust your earlier class declarations so that an Oz animal is a lion, tiger, or bear.
Add the IOzAnimal method moreScary, which produces a scarier animal (as above). Adjust the return types of previoulsy implemented methods if necessary.
Define the IOzAnimal method feed that takes a string for a person’s name. The result should be an IOzAnimal that just ate the person whose name is given.
Define the IOzAnimal method rescue that takes no arguments and returns an IOzAnimal that hasn’t recently eaten anyone.
An Oz scene consists of one person and one IOzAnimal. It is represented as an OzScene:
class OzScene { String person; OzAnimal animal; OzScene(String person, OzAnimal animal) { this.person = person; this.animal = animal; }
Implement the OzScene method moreScary, which takes no arguments and produces one with a scarier animal and the same person.
An Oz scene moves the next scene as follows:
Implement the OzScene method next, which takes no arguments returns the next OzScene according to the rules above.
Don’t forget to break up the problem into smaller pieces. For example, you might find an animalAte method of OzAnimal useful (that takes no arguments returns a string for the person that the animal recently ate).
Last update: Monday, November 1st, 2010mflatt@cs.utah.edu |