Question
Help Code this Java Please or check my Code Virtual Pet Shelter Details We're going to use TDD to drive the creation of an application
Help Code this Java Please or check my Code
Virtual Pet Shelter
Details
We're going to use TDD to drive the creation of an application that simulates you taking care of the pets in a shelter.
Include a game loop in this project, too. It should query the user, then call the appropriate method(s) onVirtualPetShelterand/orVirtualPet. In general, yourVirtualPetAppshould talk to yourVirtualPetShelter, and yourVirtualPetSheltershould talk to yourVirtualPet. Try to avoidVirtualPetApptalking directly toVirtualPetinstances, apart from accessing basic information about pets (viaget*methods).
Required Tasks to be completed in the order you feel is necessary
VirtualPetShelterApp class
- Create amainmethod that...
- implements agame loop.
- asks for user input.
- writes output to the console.
- callsVirtualPetShelter'stickmethod after each interaction
- Available user interface actions should include (at minimum)...
- feeding all the pets
- watering all the pets
- playing with an individual pet, which should display a list of pet names and descriptions, allowing a user to select one
- allow adoption of a pet, which should display a list of pet names and descriptions, allowing a user to select one.NOTE: In the past this has been a bit confusing. Keep in mind you are playing the role of a shelter worker, if a pet is adopted it will be removed from the shelter.
- allow intake of a pet, prompting the user for the pet's information, requiring the user to (at minimum) specify name and description
(Hint: you can use tab characters ("\t") to align console output in columns.)
VirtualPetShelter class
- include appropriate instance variable(s) to store the pets who reside at the shelter
- include methods that:
- return aCollectionof all of the pets in the shelter
- return a specificVirtualPetgiven its name
- allow intake of a homeless pet (adding a pet to the shelter)
- allow adoption of a homeless pet (removing a pet from the shelter)
- feed all of the pets in the shelter
- water all of the pets in the shelter
- plays (or performs some other interaction(s)) with an individual pet in the shelter
- include atickmethod that calls thetickmethod for each of the pets in the shelter, updating their needs
VirtualPet class
In addition to the requirements from
- include instance variables representing:
- name (from the above example, this might be "Tommy")
- description (from the above example, this might be "smells like a Stargazer lily fresh with morning dew")
- include a constructor that accepts a name and description
- include a constructor that, in addition to name and description, accepts default values for the pet's attributes (hunger, boredom, etc)
- Donotinclude a default (zero arguments) constructor.
Grading
Your grading will be based on three areas:
- Test Driven Development
- Working Software
- Clean Code
Test Driven Development
You should write your code by writing tests first. If you do so, each public method you write should have a unit test that covers its behavior. The test classes should also be well maintained and follow the principles of clean code. These are the things we are looking for with regards to Test Driven Development:
- 75% of your public methods (excepting themain()in your app class) should be covered by unit tests.
- The principles ofClean Codeas described below apply to your test classes.
- All tests pass.
Working Software
Working software consists of does the application run and how well you met the requirements. Of the 30 required tasks above, we need to see 25 complete for this category to be considered PASSING.
Clean Code
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:
- Keep method chains to a minimum. (Three chained methods in the entire project are permissable.)
- 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 four of the above principles for this category to be considered PASSING.
Stretch Tasks
- Consider any stretch tasks from last week's project that you did not attempt.
- Keep track of the cleanliness of individual pets' cages and offer an option in the user interface to clean pet cages
- DNA! In order to give your pets individual character, include as part of each pet's state one or more multipliers for needs so that one pet may become hungrier/thirstier/more bored slower/faster than another pet. (Tip: you could create a class to encapsulate this.)
Here is what I code so far
Public class VirtualPet { | |
private String name; | |
private int sleepy; | |
private int hunger; | |
private int boredom; | |
private int thirsty; | |
//constructor | |
public VirtualPet(String n) { | |
name = n; | |
sleepy = 1; | |
hunger = 1; | |
boredom = 1; | |
thirsty = 1; | |
} | |
//create getter methods | |
public String getName() { | |
return name; | |
} | |
public int getSleepy() { | |
return sleepy; | |
} | |
public int getHunger() { | |
return hunger; | |
} | |
public int getBoredom() { | |
return boredom; | |
} | |
public int getThirst() { | |
return thirsty; | |
} | |
//create setter methods | |
public void setSleepy(int s) { | |
sleepy = s; | |
} | |
public void setHunger(int hgr) { | |
hunger = hgr; | |
} | |
public void setBoredom(int b) { | |
boredom = b; | |
} | |
public void setThirst(int t) { | |
thirsty = t; | |
} | |
//utility methods to modify levels | |
public void modifySleepy(int s) { | |
sleepy += s; | |
} | |
public void modifyHunger(int hgr) { | |
hunger += hgr; | |
} | |
public void modifyBoredom(int b) { | |
boredom += b; | |
} | |
public void modifyThirst(int t) { | |
thirsty += t; | |
} | |
//tick method to randomize game loop | |
public void tick() { | |
sleepy += 1; | |
hunger += 2; | |
boredom += 2; | |
thirsty += 1; | |
} | |
} |
import java.util.Random; | |
import java.util.Scanner; | |
public class VirtualPetApp { | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
Random rand = new Random(); | |
System.out.println("KONO THE MUTANT LAB RAT:....Please enter your name."); | |
String name = input.nextLine(); | |
VirtualPet pet = new VirtualPet(name); | |
System.out.println("Hi " + pet.getName() + "! Let's have some fun"); | |
backStory(" Let's go!"); | |
int select; | |
do { | |
System.out.println("Pick a number."); | |
System.out.println("[0] Quit. "); | |
System.out.println("[1] Play with Kono"); | |
System.out.println("[2] Feed Kono"); | |
System.out.println("[3] Relax and watch a movie with Kono "); | |
select = input.nextInt(); | |
if (select == 0) { | |
continue; | |
} | |
else if (select == 1) { // Play with Kono | |
if (pet.getHunger() + 1 > 6) {// if hunger reaches max | |
System.out.println( | |
"Alright...That's enough. I'm running my tail off here. Get me some food before I pass out."); | |
continue; | |
} | |
if (pet.getSleepy() + 1 > 6) { // if sleepy reaches max | |
System.out.println(" I'm tired. I need some chill time. Let's go watch a movie or somethin'"); | |
continue; | |
} | |
System.out.println("Let's go out and play! Avoid that mouse trap obstacle course!"); | |
//pet.modifyHunger(1); | |
//pet.modifySleepy(1); | |
} | |
else if (select == 2) {// Feed Kono | |
// If hunger reaches minimum | |
if (pet.getHunger() - 1 < 0) { | |
System.out.println("ugggg....no more. One more bite of cheese and I'm gonna throw up."); | |
continue; | |
} | |
if (pet.getSleepy() + 1 > 6) { // if sleepy reaches max | |
System.out.println(" I'm tired. I need some chill time. Let's go watch a movie or somethin'"); | |
continue; | |
} | |
System.out.println("mmmhh mmhh delicious...cheese is my favorite."); | |
// hunger -= 1 hunger goes down. | |
//pet.modifyHunger(-1); | |
//pet.modifySleepy(1); | |
} | |
else if (select == 3) {// Chill and relax with pet | |
// If Boredom is at max. | |
if (pet.getBoredom() + 1 > 6) { | |
System.out.println("I'm bored. Let's go out and Play!"); | |
continue; | |
} | |
System.out.println("Let's watch a movie!"); | |
// boredom += 1 boredom goes up. | |
//pet.modifyBoredom(1); | |
String[] movies = new String[] { "Tom and Jerry. ", "Ratatouille ", "3 Blind Mice " }; | |
// randomize the movie it picks when selected | |
System.out.println(movies[rand.nextInt(movies.length)]); | |
} | |
else { | |
System.out.println("Invalid selection. Please select one of the numbers listed"); | |
} | |
//tick method | |
pet.tick(); | |
} while (select != 0); | |
} | |
public static void backStory(String msg) { | |
System.out.println( | |
"Kono accidentally swallowed some test solution which is causing some extreme swings in his heart rate." | |
+ " We must manage his heart by playing with him to keep his heart rate up" | |
+ " or make him relax and watch some of his favorite movies to bring his heart rate down." | |
+ " We also need to get him food to replenish his energy every once in a while " + msg); | |
} | |
} |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started