Classes


Creating Our Own Classes

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

Deitel chapter 3


Classwork


Part A

For the following, do not use previous example types such as Bunny, Cat, etc nor the types you used in the previous classwork.  Remember to name your classes for the type of creature, in the singular. Your creatures do not have to be real or zoologically accurate, but your design in the choices you make below should make some sense.

  Create a class representing some sort of creature.

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 kind of creature that likes to hunt the first type.  

For your new creature class

In your harness, create an instance of this class and give it the first of your original creatures as prey, and have it hunt and devour, then repeat the process with the second of your original creatures


Part C

 Give your second class a myBestFriend, who is of the same type, and a method swapPrey, which prints that they are swapping prey with their bestFriend, after which they should have their myBestFriend's old prey, and their myBestFriend should have their old prey.  This DOES NOT MEAN just to swap the names and other vars for the prey, swap the ACTUAL prey!!!  (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 has a prey too).