Guided Practice 1.2
Here is an example based on an exercise from HtDP/2e:
Design a data representation for the following four kinds of zoo animals:
- spiders, whose relevant attributes are the number of remaining legs (we assume that spiders can lose legs in accidents) and the space they need in case of transport;
- elephants, whose only attributes are the space they need in case of transport;
- boa constrictor, whose attributes include length and girth; and
- armadillo, for whom you must determine appropriate attributes; they need to include attributes that determine space needed for transportation.
Write a data definition for ZooAnimal. Be sure to include:
- Representation and Interpretation
- Implementation (structure definitions)
- Constructor Template
- Observer Template
- Examples
Here is a solution. But remember, no peeking! You won't get anything out of this exercise if you don't write down your solution first.
Last modified: Wed Sep 13 10:35:42 Eastern Daylight Time 2017