Description
You are walking down the street one day when you stumble across a puppy. Like, literally stumble. And so like the guilty good person you are, you take the now-injured puppy and take him to the nearby veterinarian, who directs you to a local puppy shelter. At the puppy shelter, you start chatting with the owner, and before you know it you’ve volunteered to write code for the puppy shelter! You will help the owner modernize his store by writing a Java program that allows him to track each puppy in his care.
Solution Description
For this assignment, create a file with the following name:
- java
Puppy Class:
Instance Variables
- String name holds the name of the puppy. It should have private access.
- int age holds the age of the puppy. It should have private access.
- int health holds the health of the puppy. It should have private access.
Constructors: Be sure to use constructor chaining.
- Puppy(String name, int age, int health)
- Puppy(String name)
- Assign the puppy a random age between 0 and 15, inclusive.
- Assign the puppy a random health between 5 and 35, inclusive.
- Again, make sure to use constructor chaining! HINT: Try creating a static Random field that you can use.
Methods:
- Correct public getters & setters for name, age, and health
- String toString() Returns “[name]: a puppy [age] years old with [health] health”
- boolean canAdopt() Returns true when the puppy can be adopted and false otherwise. A puppy can be adopted if its health is 50 or above.
- void fetch() Increases the puppy’s health by 1 (because it got exercise)
- void fetch(boolean inside) The parameter inside signals whether or not you’re playing fetch inside or outside. If inside, increase health by 5. If not inside, increase health by 10.
- void fetch(int distance) Distance represents how far the toy is thrown. Increase the puppy’s healthy by distance divided by 10. Truncate decimals if necessary.




