Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For my Java class please answer all the parts. Or at the very least parts c and

ID: 3844695 • Letter: F

Question

For my Java class please answer all the parts. Or at the very least parts c and d. 4) Write code for a Pet class. Part of this is shown (including the getAge method). Filin other blanks 20 points private int of pet in yearn private float weight 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, Showthe method header dearly b) Filin the set() method for the Pet class, with the given header: set name to brood to newBreed, age to newAgo, weight to nowWeight. You must check that newAgo 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 ob. void net (String new Name, String newBreed, int newMe, float new- Weight) c) In the public dass below, write Java statements to declare an object caled myFavPet of the class Pet, and set the name of myFavPet to "Lassie breed to "Snake age to 3, weight to 45.6. public class Yun l public static void main (String args) d)Also in the public class, write a method with this header: it takes as arguments two Pet ob- jects, and returns the one which is older (ie, has the larger age) If the ages are identical it returns the first Pet object (onePet Pet older Pet (Pet one Pet, Pet other et)

Explanation / Answer

a)//Just writing the constructor (not mentioning whole class)

Pet()
{
this.name = "Fido";
this.breed = "spider";
this.age=1;
this.weight = 0.5;
}

b)

void set(String newName, String newBreed, int newAge, float newWeight)
{

if(newAge <=0 || newWeight <= 0.5)
{
System.out.println("Either Age or Weight is not in allowe range");
}

else
{
this.name = newName;
this.breed = newBreed;
this.age = newAge;
this.weight = newWeight;
}
}

c) public class Yum{
public static void main(String args[])
{
Pet myFavPet = new Pet();
myFavPet.set("Lassie","Snake",3,45.6);
}
}

d) Pet olderPet(Pet onePet, Pet otherPet)
{

int> int otherAge = otherPet.getAge();

if(oneAge == otherAge || oneAge > otherAge)
{
return onePet;
}

else if(otherAge > oneAge)
{
return otherPet;
}
}