Classes


Creating Our Own Classes

Dog.java
DogHarness.java
Bunny.java
BunnyHarness.java
Cat.java

Deitel chapter 3


Classwork


Part A

  Create a class modeling some type of creature, (do not use previous example types such as Bunny, Cat, etc).  Remember to name your class for the type of creature, in the singular. (Your creature does not have to be real or zoologically accurate, but your design in the choices you make below should make some sense)

For your new creature class

In a separate harness class, in a main,

(This may look a lot like BunnyHarness.)


Part B

Create a second new creature class. You will test it in the same test harness.  This class represents a creature that keeps the first type as a pet.  

For your new creature class

In your harness, test out this creature, including its interactions with the creature from part A.   Your methods in the second class will blow up if you don't give your second creature a pet before  calling play or eat, so make sure you give this creature a pet!!


[EC]  Give your second class a myBestFriend, who is of the same type, and a method swapPets, which prints that they are swapping pets with their bestFriend, after which they should have their myBestFriend's old pet, and their myBestFriend should have their old pet.  This DOES NOT MEAN just to swap the names and other vars for the pets, swap the ACTUAL pets!!!  (hint: if you had a glass of milk and a glass of wine, could you swap their contents using just those two glasses...?)  Test this in main (it will only work if you give them a myBestFriend in main before you call the method, and the myBestFriend should have a pet too).