Writing classes

Dog class

Write a class to represent a dog.

A dog has a name, and can be hungry.

Constructor: takes one argument: the name of the dog. Initializes appropriately (a dog is initially hungry).

 

Methods:

bark: Prints "WOOF" if the dog is hungry, and "woof" if not.

eat: takes one argument: the food fed to the dog. The dog eats if it is hungry and if the food given is not the same as at the last previous meal. Prints a message telling whether the dog eats or not. Returns true if the dog eats, and false if not.

fetch: The dog plays fetch if it is not hungry. Prints a message telling whether the dog plays fetch or not.

rollOver: The dog rolls over if it is not hungry. Prints a message telling whether the dog rolls over or not.

After fetching or rolling over 5 times, the dog gets hungry.

 

Simulation class

Create a dog, and have it bark, eat, fetch, roll over several times to test the features of the dog class.