Question: I need part c and D answered for my Java class Write code for a Pet class. Part of this is shown (including the getAge

 I need part c and D answered for my Java class
I need part c and D answered for my Java class

Write code for a Pet class. Part of this is shown (including the getAge method). Fill in other blanks. 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. to, 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 net (String newName, String new, int newAge, float newWeight) { } c) In the public class below, write Java statements to declare an object called myFavPet of the class Pet, and set the name of myFavPet to "Lassie

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!