CSAlpha Assignment 6: Zoology Classification

Create a file called assign6.txt. You will use this file to paste your code and answer written questions. Please clearly label each section.

If you have any questions regarding the assignment or see any errors in the assignment writeup, please contact me.

Concepts and Resources

🎉 Congratulations!🎉 At this point in the course, you've fully learned the four main principles of Object Oriented Programming: encapsulation, abstraction, inheritance, and polymorphism.

This week, we learned about inheritance and polymorphism. Moreover, our look into abstract classes and interfaces gives us a better understanding of abstraction and its uses. This assignment will test your comprehension of those topics and features of Java as an OOP language and help you attain a better sense of when to use each type of structure.

 

List of Important Concepts:

 

Resources:

 

Written Questions

  1. Describe the differences between a class, an abstract class, and an interface.

  2. What are some situations that upcasting would be useful? What about downcasting?

  3. When is the @Override annotation needed?

  4. List one concrete example of when an abstract class would be used as opposed to an interface and vice versa.

  5. Examine the following code.

    For which functions is the class Ferrari required to provide its own implementation?

Write your answers in assign6.txt

 

Core Assignment: Zoology Classification

This assignment will be much more open-ended than previous assignments so that you can fully exercise the software engineering skills you have gained over the past weeks. Although you still have to complete the required portions of the assignment, I highly recommend you to be as creative with them as possible, attempting to mold your code to something that would be truly applicable in the real world.

Something to think about while completing the assignment: most of the time, the difficulty doesn't come from writing the code itself, but being able to design an effective and useful system before you even touch the keyboard. Planning beforehand decides if your project will be organized and efficient or if it will be a heap of spaghetti code.

After this assignment, you will work on a final CSAlpha project for approximately three weeks. That project requires your utmost creativity and effort, using all the concepts that we have learned thus far. I advise you to give your best shot on this assignment in preparation for that project.

 

Milestone 1: Picking a theme

Your job this time is to create a suite of classes that represents a small hierarchy of objects branching from one main abstract object. The title of this assignment is "Zoology Classification", but you can pick any theme you would like. In the next milestones, I will give some examples for the default theme, but you can adjust those examples to your own theme. Be creative!

Example: The theme is animals.

 

Milestone 2: Creating your abstract parent class

At the top of your hierarchy is one abstract class that will help group these closely related classes and objects together. The reason why we want an abstract class here is because we want to implement some functions but want to require subclasses to implement others.

Below are some requirements for your base abstract class:

Example:

 

Milestone 3: Extending into child classes

Now you will flesh out your hierarchy by adding many child classes extending the abstract parent class.

Below are some requirements for your children classes:

Example: Some child classes of Animal could be Pig, Horse, etc.

 

Milestone 4: Implementing a general interface

Although you have already provided functions and fields that are shared among all these subclasses, perhaps you want to add more functionality that is not strictly for them. For example, the Cloneable interface. Although you may want all animals in the zoo to share the ability to create copies of themselves, that's not the only group of classes that may want the ability to clone; it may be useful to cars, people, etc. This new functionality should be created using an interface to emphasize that very point.

Note that if your abstract parent class implements an interface, the subclasses will be required to implement the declared functions of the interface. This is helpful because the subclasses won't need to independently implement the interface.

Below are some requirements for your interface:

Example: Communicate, an interface that allows you to send and receive messages from the object,

Please define an interface different from the example one.

 

Milestone 5: Making a small driver

After you've finished the code for all your subclasses, it's time to make a small driver to test all these parts in conjunction. If you've been doing some testing after each milestone, this section will not be difficult.

Here are the steps for the creation of your driver, which you will be placing in the Main class main method:

Amazing job! You went from writing tiny programs to creating a complex system/hierarchy that has real-world application. Be proud of yourself and all that you have achieved in this course!

Paste your code in assign6.txt

 

Assignment Extension: Starting a New Zoo

The driver surely tests if your code is working, but it doesn't make use of the hierarchy as much as it could. For this extension, you will be creating a separate class to manage a 'zoo' of all objects of your subclasses and make it easier to use your hierarchy . The Zoo class and its requirements refer to the animals theme example, but call your management class and its fields and functions according to the theme you picked.

Here are the required attributes for this extension class:

You may have to hardcode much of the branching logic for identifying the animal subclass and running functions. However, if you find a way to do it in a cleaner way, props to you! That will require some knowledge of data structures and a few other topics outside the scope of this class.

Paste your code in assign6.txt

 

Additional Practice

Create another hierarchy or make a simple game that employs concepts of inheritance and polymorphism.