Instead of the normal HW 12 below, you may elect to implement in Java the execute function of HW 11 — no GUI, and no need to parse strings. Your execute should be a method of a DefOrAssignOrExpr class, and you'll certainly need an Expr class with a evaluate method. To test your evaluator, instantiate DefOrAssignOrExpr directly instead of parsing parenthesized input.
Students who implement a Mini Scheme interpreter in Java before the HW 12 due date will be excused from all further homework. For this alternate project, you may use whatever Java environment you prefer.
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 abstract class OzAnimal and adjust your earlier class declarations so that an Oz animal is a lion, tiger, or bear.
Add the OzAnimal method moreScary, which produces a scarier animal (as above). Adjust the return types of previoulsy implemented methods if necessary.
Define the OzAnimal method feed that takes a string for a person's name. The result should be an OzAnimal that just ate the person whose name is given.
Define the OzAnimal method rescue that takes no arguments and returns an oz-animal that hasn't recently eaten anyone.
Hint: the answer should be especially short, and it should use the name "no one".
An Oz scene consists of one person and one OzAnimal. 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: Thursday, November 13th, 2003mflatt@cs.utah.edu |