A Swimmer is either
Implement classes for all three kinds of swimmers, and group them under suitable abstract classes. Put the constructor arguments in the above orders. Note that all swimmers have a length.
Implement a List datatype to represent a collection of Swimmers. The datatype should include Empty and Cons variants.
Implement a longer method of List that takes a number and returns a list of all of the Swimmers in the original list that are longer than the given number.
You may need to add new methods to one or more other classes, but avoid redundant code where possible.
Implement a sleek method of List that returns a list of all of the Swimmers in the original list that are longer than 5, not including any turtles that are older than 31.
You will need to add new methods to some other classes, but avoid redundant code where possible.
Implement a gills method of List that returns a list of all of the Fish in the original list.
You will need to add new methods to some other classes, but avoid redundant code where possible.
Add a new kind of Fish to the variants of Swimmer:
Note that anything that's true of all fish will be true of a Piranha.
Implement a deadly method of List that returns a list of all of the Piranhas and Crocodiles in the original list.
Again, you will need to add new methods to other classes.
Implement a oneBite method of List that works when the list contains only Piranhas and Crocodiles. The oneBite method takes a number and returns true if all of the swimmers in this list have a maximum bite size at least as large as the number.
To implement this method, you will need to add an interface to your program and change some existing classes to implement the interface.
Last update: Friday, November 21st, 2003mflatt@cs.utah.edu |