For this exercise, you will be given a project file digital_pet containing two (2) classes, the DigiPet class andthe DigiPetTester class.Every DigiPet has five fields:- name- lifespan (in cycles) – max age- age (in cycles) – current age- mood (2 = joyful, 1 = happy, 0 = neutral, -1 = sad, -2 = angry)- size – current size of pet (size ≥ 1)A DigiPet has a default constructor, overloaded constructor, and some various methods which allow one tointeract with it or modify its state.Poke or pet increases or decreases its mood.Feed or exercise increases or decreases its size by a specified amount.Every time you interact with the digipet (poke, pet, feed, exercise), its age increases. When the age reaches thelifespan, it dies (or becomes a zombie).You need to modify and customize the DigiPet class as follows:- Implement the overloaded constructor: Initialize all five fields. Use the values passed as parameters toinitialize name and lifespan. Use the same default values that the default constructor uses to initializethe other three fields (age, mood, and size).- Implement poke(): Decrement mood by 1. Check and make sure mood stays larger than -2. Call themakeOlder() method to make the pet older by one cycle. (Note that the makeOlder() method isalready implemented for you; you simply need to call it.)- Implement pet(): Increment mood by 1. Check and make sure mood stays smaller than 2. Call themakeOlder() method to make the pet older by one cycle.- Implement feed(int amount): Increases the pet’s size by the amount (passed as a parameter to themethod). Call the makeOlder() method to make the pet older by one cycle.- Implement exercise(int amount): Decreases the pet’s size by the amount. If the resulting size issmaller than 1, print a message "No more energy!" and set the size to 1. Call the makeOlder() methodto make the pet older by one cycle.- Modify showPet(): Customize it any way you like but with the following requirements: It must showthe name, age, and lifespan. It must depict the size and mood in some way (be creative).Optional: Feel free to tweak the behavior or add behaviors as long as they make sense and you let me know.To let me know what you changed or added, write comments for the methods and also display for the user theappropriate instructions if you make changes or additions. You will need to add cases to the switch statementand modify the DigiPetTester main method to support additional behaviors.
For this exercise, you will be given a project file digital_pet containing two (2) classes, the DigiPet class and
the DigiPetTester class.
Every DigiPet has five fields:
- name
- lifespan (in cycles) – max age
- age (in cycles) – current age
- mood (2 = joyful, 1 = happy, 0 = neutral, -1 = sad, -2 = angry)
- size – current size of pet (size ≥ 1)
A DigiPet has a default constructor, overloaded constructor, and some various methods which allow one to
interact with it or modify its state.
Poke or pet increases or decreases its mood.
Feed or exercise increases or decreases its size by a specified amount.
Every time you interact with the digipet (poke, pet, feed, exercise), its age increases. When the age reaches the
lifespan, it dies (or becomes a zombie).
You need to modify and customize the DigiPet class as follows:
- Implement the overloaded constructor: Initialize all five fields. Use the values passed as parameters to
initialize name and lifespan. Use the same default values that the default constructor uses to initialize
the other three fields (age, mood, and size).
- Implement poke(): Decrement mood by 1. Check and make sure mood stays larger than -2. Call the
makeOlder() method to make the pet older by one cycle. (Note that the makeOlder() method is
already implemented for you; you simply need to call it.)
- Implement pet(): Increment mood by 1. Check and make sure mood stays smaller than 2. Call the
makeOlder() method to make the pet older by one cycle.
- Implement feed(int amount): Increases the pet’s size by the amount (passed as a parameter to the
method). Call the makeOlder() method to make the pet older by one cycle.
- Implement exercise(int amount): Decreases the pet’s size by the amount. If the resulting size is
smaller than 1, print a message "No more energy!" and set the size to 1. Call the makeOlder() method
to make the pet older by one cycle.
- Modify showPet(): Customize it any way you like but with the following requirements: It must show
the name, age, and lifespan. It must depict the size and mood in some way (be creative).
Optional: Feel free to tweak the behavior or add behaviors as long as they make sense and you let me know.
To let me know what you changed or added, write comments for the methods and also display for the user the
appropriate instructions if you make changes or additions. You will need to add cases to the switch statement
and modify the DigiPetTester main method to support additional behaviors.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images