Question: Create a Java program that consists of two files, one Pet class, and a PetCaretaker class for using the Pet class. The Pet class should
Create a Java program that consists of two files, one Pet class, and a PetCaretaker class for using the Pet class.
-
The Pet class should be in a file called Pet.java, and it should have all of the standard accessor and mutator methods associated with any object to promote information hiding and encapsulation.
-
The Pet class should have member variables for: alive, breed, name, happy, and hungry.
-
Note: the happy and hungry variables should be type int, that represent a scale from 1 to 100, with 100 being the happiest or hungriest. If the Pet is too hungry (say > 75), no amount of play will make it happy, and if the Pet is too unhappy (say <= 25), then it won't have an appetite either.
-
Each time we execute the loop, the Pet will lose 8 happy points and gain 10 hungry points.
-
In addition, your Pet class should have member functions feed that should subtract 25 hungry points, and play that should add 20 happy points (don't forget that your scale is 1-100!).
-
Add the following code to your program, which will allow your program to pause in between loops; just add the following code inside of your loop to pause for two seconds for each execution of the loop:
try{ Thread.sleep(2000);
} catch(InterruptedException ie) {
System.out.println("InterruptedException should not have
occurred."); }
The PetCaretaker class should merely consist of a main method that instantiates a Pet object and loops continuously, checking on the status of our Pet, and displaying a list of options to work with the Pet object. We should feed it when it gets hungry, and play with it when it isn't happy. This would be accomplished by merely calling two additional methods to play with and feed (you should create these two methods in your Pet class based upon the description above) the Pet object.
You can be a little creative and add more messages if you would like, but you should minimally provide the functionality described herein.
Example Output:
Welcome to the PetCaretaker. Please enter the name of your dog: Snoopy
What breed is Snoopy: Beagle Snoopy is alive, happy, and full....
*************************************
* Enter "Feed" to feed Snoopy *
* Enter "Play" to play with Snoopy *
* Enter "Ignore" to ignore Snoopy *
* Enter "Exit" to exit this program *
************************************* :>Feed
Snoopy is being fed. ..... Many executions of the code later ....
Snoopy is alive, very unhappy, and starving....
************************************* * Enter "Feed" to feed Snoopy * * Enter "Play" to play with Snoopy * * Enter "Ignore" to ignore Snoopy * * Enter "Exit" to exit this program * ************************************* :>Play
Snoopy is too hungry to play! The Beagle is no longer alive, why did you let Snoopy die? Thank you for using the PetCaretaker program.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
