Question: Write code for a Pet class. Part of this is shown (including the getAge method). Fill in other blanks. Class Pet {Pet private String name;/ame
Write code for a Pet class. Part of this is shown (including the getAge method). Fill in other blanks. Class Pet {Pet private String name;/ame of pet private String breed;//type of pet (dog, cat,//etc) private int age;//age of pet in years private//; must be > = 0 private float weight;//min weight//must be > = 0.5 int getAge () {return age;}//methods for the Pet class that you will need//to fill in go here... a) write a constructor method for the Pet class, to set the default name to "Fido", the default breed to "spider", the default age to 1, and the default weight to 0.5. Show the method header clearly. b) Fill in the set() method for the Pet class, with the given header; set name to newName, breed to newBreed, age to newAge, weight to newWeight. You must check that newAge is > = 0, and weight > =0.5. If either newAge or newWeight is not in the correct range, print an error message and return immediately, without changing any of the member variables of the Pet object. void set (String newName string new Breed, int newAge, float. new Weight) {
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
