Question: Need help with a java class and I don't really know where to start the documentation for the class is listed below zoo Class Zoo

Need help with a java class and I don't really know where to start the documentation for the class is listed below

zoo

Class Zoo

java.lang.Object

zoo.Zoo

public class Zoo extends java.lang.Object This class models a simple zoo with four cages and four different types of animals (one in each cage). It also has a zoo keeper that tends to the animals as instructed by client code through the various public methods. Lastly, the zoo has a pantry in which different types of foods are stored for the animals.

Field Summary

Fields Modifier and Type Field and Description static int DOLPHINLOCATION The cage number for the Dolphin in the zoo. static int ELEPHANTLOCATION The cage number for the Elephant in the zoo. static int PENGUINLOCATION The cage number for the Penguin in the zoo. static int TIGERLOCATION The cage number for the Tiger in the zoo.

Constructor Summary

Constructors Constructor and Description Zoo() Constructor for Zoo which creates all necessary elements for the zoo simulation as described in the class-level javadoc.

Method Summary

All MethodsInstance MethodsConcrete Methods Modifier and Type Method and Description boolean cleanCage(int cage) Cleans the cage of the Animal at the specified location if sufficient energy is available to the keeper. int endDay() Ends a day at the Zoo. boolean feedAnimal(int cage, ZooPantry.AllowableFoods foodId) Feed an Animal found in the given cage location a Food in the given foodCrate location only if there is enough food in the foodCrate and the Keeper has enough energy to expend on the Food's exhaustion cost. boolean giveTigerBall() ZooKeeper gives ball to the Tiger if there is sufficient energy available. boolean swimWithDolphin() Keeper Swims with the Dolphin if sufficient energy is available and updates state information of both ZooKeeper and Dolphin accordingly. java.lang.String toString() Generates a String representation of the Game.

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

Field Detail

ELEPHANTLOCATION

public static final int ELEPHANTLOCATION The cage number for the Elephant in the zoo.

See Also: Constant Field Values

DOLPHINLOCATION

public static final int DOLPHINLOCATION The cage number for the Dolphin in the zoo.

See Also: Constant Field Values

PENGUINLOCATION

public static final int PENGUINLOCATION The cage number for the Penguin in the zoo.

See Also: Constant Field Values

TIGERLOCATION

public static final int TIGERLOCATION The cage number for the Tiger in the zoo.

See Also: Constant Field Values

Constructor Detail

Zoo

public Zoo() Constructor for Zoo which creates all necessary elements for the zoo simulation as described in the class-level javadoc. Upon completion of the constructor, this Zoo's state should include one of each Animal type, a ZooPantry, a ZooKeeper, and an initial score of 0.

Method Detail

toString

public java.lang.String toString() Generates a String representation of the Game. Creates String with each Animal followed by newline, each Food followed by newline, and Keeper energy and score. Each of these sections is ended with a newline. See example output for format.

Overrides: toString in class java.lang.Object Returns: String of current state of the game.

endDay

public int endDay() Ends a day at the Zoo. Sends all Animals to sleep. Randomly delivers a food to the ZooPantry, and resets the ZooKeeper's energy level for the next day.

Returns: Total score for the end of the current day, which is the sum of each Animal's score for the day.

feedAnimal

public boolean feedAnimal(int cage, ZooPantry.AllowableFoods foodId) Feed an Animal found in the given cage location a Food in the given foodCrate location only if there is enough food in the foodCrate and the Keeper has enough energy to expend on the Food's exhaustion cost. If possible, feeds Food to the Animal, consumes the Food, and reduces Keeper energy by Food's exhaustion cost. Returns true if Food successfully given to Animal, false if not.

Parameters: cage - Cage location of Animal to feed, must be a valid cage location per the public constants defined in by the Zoo. foodId - The kind of Food to feed the Animal in the specified cage. Returns: Success of feeding Animal. Should be false if there is sufficient food, the keeper lacks enough energy or if the cage value is invalid.

cleanCage

public boolean cleanCage(int cage) Cleans the cage of the Animal at the specified location if sufficient energy is available to the keeper. If energy is available the keeper cleans the cage and expends energy.

Parameters: cage - Cage location to be cleaned, must be a valid cage location per the public constants defined in by the Zoo. Returns: Success of cleaning the cage. False if the keeper lacks sufficient energy to clean or if the cage location specified is invalid.

swimWithDolphin

public boolean swimWithDolphin() Keeper Swims with the Dolphin if sufficient energy is available and updates state information of both ZooKeeper and Dolphin accordingly.

Returns: True if the keeper was able to swim with the dolphin successfully, false otherwise.

giveTigerBall

public boolean giveTigerBall() ZooKeeper gives ball to the Tiger if there is sufficient energy available. If energy is available, the ZooKeeper will update her energy and give the ball to the Tiger.

Returns: Returns true if the Keeper was able to give the ball; false if not.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!