Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / Create Pet class that keeps track of the name, age, weight, type of animal, and breed for records at an animal clinic

Create Pet class that keeps track of the name, age, weight, type of animal, and breed for records at an animal clinic

Computer Science

Create Pet class that keeps track of the name, age, weight, type of animal, and breed for records at an animal clinic.

 

/**

  Pet class (complete comments)

  @author

  @since

 

*/

class Pet

{

  // keep track of the name, age, weight, type of animal, and breed of the pet

  private String name;

  private int age;

  private double weight;

  private String type_of_animal;

  private String breed;

 

  // Write 2 constructors, accessor (get) methods, and a toString method. Use good commenting.

  Pet()

  {

    this.name = "";

    this.age = 0;

  }

  Pet(String name, int age)

  {

    this.name = name;

    this.age = age;

  }

  public void setName(String name)

  {

    this.name = name;

  }

  public void setAge(int age)

  {

    this.age = age;

  }

  public void setWeight(double weight)

  {

    this.weight = weight;

  }

  public void setTypeOfAnimal(String type_of_animal)

  {

    this.type_of_animal = type_of_animal;

  }

  public void setBreed(String breed)

  {

    this.breed = breed;

  }

  public String getName ()

  {

    return this.name;

  }

  public int getAge ()

  {

    return this.age;

  }

  public double getWeight()

  {

    return this.weight;

  }

  public String getTypeOfAnimal ()

  {

    return this.type_of_animal;

  }

  public String getBreed()

  {

    return this.breed;

  }

   

  public String toString ()

  {

    return "Name: "+getName()+"nAge: "+getAge()+"nWeight: "+getWeight()+"nType Of Animal: "+getTypeOfAnimal()+"nBreed: "+getBreed();

  }

}

 

  // Don't forget to complete the main method in the TesterClass below!

 

 

public class TesterClass

{

  // main method for testing

  public static void main(String[] args)

  {

   // Create 3 Pet objects and test all your methods

    Pet p = new Pet ("Shaggy",23);

    p.setBreed("German Shepherd");

    p.setTypeOfAnimal("Domestic dog");

    p.setWeight(28);

    System.out.println(p.toString());

    System.out.println("Weight of pet: "+p.getWeight());

  }

 }

 

Hi there. Please help me to add one more accessor (get) methods for each variable and 2 more main method creates three pet object in this java code. Thank you.

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Related Questions