Virtual Pet Create a virtual pet. Maybe we can make this a fad! Setup(Links to an external site.) Please navigate to Git Hub Classroom, which can be foundhere(Links to an external site.), then please...


Virtual Pet


Create a virtual pet. Maybe we can make this a fad!


Setup(Links to an external site.)



Classes(Links to an external site.)



  • You will need to create aVirtualPetclass.


  • VirtualPetApplicationwill house themainmethod. This is the starting point when the application runs.


  • Stretch goalBuild out unit tests in theVirtualPetTestclass to test the behaviors placed inVirtualPet


Details(Links to an external site.)


Create a virtual pet application. This is your version of a Tamagotchi or DigiPet! This might seem like a daunting task, but we can break it down.


Think of which instance variables and methods you will need. We give suggestions below. Remember that instance variables represent the state of your pet. Methods represent the behavior of your pet, which would include its responses to you feeding or playing with it.


Most games include what is called agame loop, a loop which updates everything in the game, representing the passage of time. We exit this loop when something happens that should cause the game to end. Include atick()method (think clocks, not parasites) in yourVirtualPetclass representing the passage of a unit of time. This should do things like update instance variables ofVirtualPetthat are time dependent, such as hunger or thirst. You should call thetick()to represent the passage of time after each interaction with the user.


There is always some confusion with thistick()method. It has some flexibility, what you are doing is changing the properties of your Virtual Pet at some rate in this method…every time this method is called, those properties specified in this method would update.


Ideas(Links to an external site.)


Attributes (instance variables) that a virtual pet might have, along with some ideas for activities (methods) that might address them are:



  • hunger (feed it)

  • thirst (water it)

  • waste (let it out to the bathroom)

  • boredom (play with it)

  • sickness (take it to the doctor)


Your methods should cause the appropriate instance variables to update - for instance, if you have afeed()method, it might makehungergo down, but makethirstgo up.


Attributes that might update whentick()is called:



  • boredom increasing

  • hunger increasing

  • sleepiness increasing


If you play with the pet, perhaps that makes it more tired. Have fun with this part!Tip: You can use your README.md file to keep a list of features you’d like to incorporate.


Also, remember that more features!=better. Pick a focus for your pet. Maybe go with a theme.


Your user interface should live in themainmethod of theVirtualPetAppclass. YourVirtualPetclass should not be writing messages to the console or reading user input. These are responsibilities of theVirtualPetAppclass.


An example user interface is below (yours doesn’t need to match this!):



Horace the Hippo Hunger: 27 Thirst: 5 Boredom: 5 Tiredness: 50 What do you want to do? 1. Feed Horace 2. Water Horace 3. Play with Horace 4. Put Horace to sleep 5. Do nothing > 1 You feed Horace.


Required Tasks(Links to an external site.)



  • VirtualPet class

    • Create atick()method that represents the passage of time.

    • Create at least three instance variables (aka attributes aka properties aka fields).

    • Create at least three methods (messages you send to your pet).



  • VirtualPetApp class

    • Create amainmethod that…

      • implements agame loop.

      • asks for user input.

      • writes output to the console.






Grading(Links to an external site.)


Your grading will be based on two areas:



  • Working Software

  • Clean Code


Working Software(Links to an external site.)


Working software consists of does the application run and how well you met the requirements. Of the 6 required tasks above, we need to see 5 complete for this category to be considered PASSING.


Clean Code(Links to an external site.)


Clean code deals with how your code is written. Is it readable, easy to understand, formatted, and not littered with commented out code? These are the things we will be looking for:



  • Formatted code - This is the simplest task, useCTRL + ALT + Lto have IntelliJ format your code for you.

  • Variable and Method Names - Variables and method names should inform the reader what the purpose of the variable or method is. Afeed()method that affects thehungerfield variable in yourVirtualPetclass is an example of good naming.

  • If you use descriptive method and variable names, your reliance on comments can be reduced. And you should never leave blocks of commented out code in your committed code.


We are looking for adherence to all three of the above principles for this category to be considered PASSING.


Stretch Tasks(Links to an external site.)




  • Give the pet the ability to take care of some of its own needs.


    Pets are not robots - they usually have some sort of self-determination! Whentick()is called, you might want to have your pet take a look at its needs and address one, prioritizing whichever need is highest. You could also make your pet uncooperative - when the user tries to feed the pet, for example, you might make the pet refuse to eat if it is bored. Remember how we created an instance of theRandomclass to create a random number generator? You might want to incorporate that.




  • Create a visual representation of your pet.


    Rather than using numbers to convey your pet’s status, you could have some sort of visual representation of the pet. I.e., instead of printinghunger: 50, you could use smileys orASCII art(Links to an external site.)to show hunger whenhunger >= 50.




    >=




  • Assign favorite foods to your pet, and add a parameter specifying the type of food to the method you use to feed your pet. Your pet should react accordingly. You could also decide which foods it doesnotlike.




  • Create Unit Tests!




Hints(Links to an external site.)


Don’t try to tackle everything at once! Break this project up into smaller chunks, and you will find that they are all manageable. (Getting comfortable testing as you go will make this project more manageable!!)

Oct 14, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here