Lions and Tigers and Bears, Oh My!

Purpose

To design a Zoo, utilizing the strategies learned in previous labs and lectures, such as abstract classes, combined with a new class of self-referential data, a list. This lab intends to show how you can combine these two strategies to easily implement even complicated class heirarchies by thoroughly thinking through the data definition and knowing how to implement that definition in the frameworks of Java.


Part 1 - Who let the Dogs out?

In the first section of the lab, you should download the code (exe) for the project. This code already includes both of the jar files needed to get the project running in Metrowerks as well as the Metrowerks project file and all the fixins. Yummy! The code should look familiar, a large part of it was done in the previous lab. Look over this code and if there are any questions, ask the nearest TA or tutor for help. The code should run and display some "pretty boxes" without any modification. The project currently has an implementation of the Animal class heirarchy we developed last time.

 

Part 2 - One Fish, Two Fish, Red Fish, Blue Fish

But we don't want to only be able to deal with single animals! What if we are starting a large collection of lions? We want to be able to add these lions to a long list of lions and then search that list for a lion with a particular name, Simba for example. How do we do this? We need self-referential data! What is self-referential data? Self-referential data is data that is defined in terms of itself. This is how we will view our list. After some data analysis, we discover that there are two kinds of Lists, EmptyLists and NonEmptyLists (we will use Cons and Empty). This discovery should remind of us something. A list is one of two types, in the same way that an animal was one of three types! We have a parent and a child class! Do some data analysis and method analysis on each of the child classes.

  • What do they have that is different from one another?
  • What types of things are the same?
  • What belongs in the parent class List?
  • What goes in only one of the two children, either ConsLion or EmptyLion?
  • What does the UML Diagram look like?



Part 3 - Have a little help from our friends

We now have the two classes, the implementation of all the basics we need for a List of lions. But it seems pretty useless unless we create a few extra methods to be able to process these lists of ferocious Kings of the Jungle. Come up with a few ideas of some methods that would be useful for this List of lions. If you're having trouble, consider the following.

  • What if we want to print the list of lions in order by their name?
  • How can we determine if Simba is still in his cage, or if he's no longer with the rest of the lions?
  • Can we easily find the heaviest lion, or the lightest?
  • If we decide to make lion steaks, how many pounds will we have using all the lions?

Implement a solution to one of the above problems. If you're ambitions, implement solutions to all of them! They all could be very useful and possibly prevent someone from being eaten!

 

Part 4 - Animal House

It's all very good to have a list of lions, but we still haven't reached our true goal. We want to create a zoo, not just a list of lions. It may look as if we have to start all over again, but because of our careful data analysis and use of a class heirarchy, the change isn't so hard to make!

  • What is the main difference between our two lists?
  • Does this lead to a lot of changes?
  • Does the fact that lion is a subclass of animal help us at all?

 

 

Conclusion

We have walked through the design and implementation of a problem involving complicated data. Not only do we have self-referential classes of data, but also class heirarchies. The Data Analysis was a difficult task, but once completed lended itself easily to the implementation of the classes. In addition, this well thought out Data Analysis also leads to structured data that others can understand, as well as a program that is easily adaptable.