Hi There!

I'm Dan Schlegel, an Associate Professor in the Computer Science Department at SUNY Oswego

Assignment 1

This is a light and easy introduction into the project. Remember to read the complete project description in order to understand the general context and for further details. You can download a jar file (and required sample input file) for a project which meets the requirements of the project description but will not follow the same implementation as we will use in this course.

In this first assignment you will create two classes, Room and Animal, that have the following properties:

  • A Room can contain ten Animals, stored in an array;
  • Every Animal must know about its Room (i.e., it needs to have a Room reference);
  • Every Room and every Animal must have a name;
  • Room has a public String toString() method that returns the name of the Room and the names of all Animals in the Room. (hint: Room’s toString() method should call Animals’ toString() methods);
  • The Room class should have a public constructor that takes a String (the name of the Room), and a public void addAnimal(Animal a) method that adds an Animal to the Room. Be sure to think about what needs to change about the Animal being assigned Room, and the Room it is being assigned to;
  • The Animal class should have a public constructor that takes a String (the name of the Animal).

Be sure to think about cases of failure – what should you do when an operation cannot be performed? See the project description for details.

In this assignment you may not use any static methods or fields – we will need the ability to have more than one Room and Animal as the project moves forward! Remember to use good practices. For example, don’t access fields directly from other classes, use getter/setter methods.

Create a third class (call it Assignment1) which contains a main method implementing test cases for the above criteria. Be sure it contains tests for the “hard” cases, e.g., testing Room’s toString where a Room contains more than one Animal.

You will submit your assignment via Blackboard. I will be using my own driver class which tests various aspects of this assignment, so make sure your public methods/fields/classes are named exactly as described above.