We are going to create a constructor and some methods for our Dog class, so that Baxter, Lucy, and Max can play together. Here’s what we need: A constructor that takes in a name (String), age (int)...

1 answer below »

We are going to create a constructor and some methods for our Dog class, so that Baxter, Lucy, and Max can play together. Here’s what we need:






  • A constructor that takes in a name (String), age (int) and a “tired” value (boolean). The order matters here!




  • A play() method. play() should print that the dog is playing and then make the dog tired. If the dog is already tired, it cannot play (print this out to tell the user)




  • A nap() method. nap() should print that the dog is napping and then make the dog not tired. If the dog is already not tired, it cannot nap (print this out to tell the user)




  • A birthday() method. birthday() should print out a happy birthday message for the dog and increase the dog’s age by 1.




  • A toString() method. toString() should return a String that looks like this. This example is for a Dog named Spot who is 9 years old and is not tired:






“Dog: Spot age: 9 tired: false”




Testing


After you think you are done, run the dog simulation by executing java Dog in your cloud shell. Follow the code in the main method and make sure it is doing what you’d expect! (i.e. Lucy is too tired to play, and Baxter is too excited to nap (this happens twice). Baxter should also celebrate his 4th birthday.)





Answered Same DayMar 29, 2021

Answer To: We are going to create a constructor and some methods for our Dog class, so that Baxter, Lucy, and...

Neha answered on Mar 30 2021
149 Votes
public class Dog
{
// Instance Variables
String name;
boolean tired;
int a
ge;

// Constructor Declaration of Class
public Dog(String name, int age, boolean tired)
{
this.name = name;
this.age = age;
this.tired = tired;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public boolean getTired()
{
return tired;
}
//play method to find out whether dog can play or not
public String play()
{
if...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here