Menu

Draw Uml Class Diagram Petrecord Catrecord Dogrecord Birdrecord Following Code Start Petre Q43902145

Draw a UML class diagram for PetRecord, CatRecord, DogRecord andBirdRecord in the following code:

//start of PetRecord class

public class PetRecord {

private String name;

private int age;

private double weight;

public String toString() {

return (“Name: ” + name + ” Age: ” + age + ” years” + “nWeight:” + weight + ” pounds”);

}

public PetRecord(String initialName, int initialAge, doubleinitialWeight) {

name = initialName;

if ((initialAge < 0) || (initialWeight < 0)) {

System.out.println(“Error: Negative age orweight.”);

System.exit(0);

} else {

age = initialAge;

weight = initialWeight;

}

}

public void set(String newName, int newAge, double newWeight){

name = newName;

if ((newAge < 0) || (newWeight < 0)) {

System.out.println(“Error: Negative age orweight.”);

System.exit(0);

} else {

age = newAge;

weight = newWeight;

}

}

public PetRecord(String initialName) {

name = initialName;

age = 0;

weight = 0;

}

public void setName(String newName) {

name = newName;

}

public PetRecord(int initialAge) {

name = “No name yet.”;

weight = 0;

if (initialAge < 0) {

System.out.println(“Error: Negative age.”);

System.exit(0);

} else

age = initialAge;

}

public void setAge(int newAge) {

if (newAge < 0) {

System.out.println(“Error: Negative age.”);

System.exit(0);

} else

age = newAge;

}

public PetRecord(double initialWeight) {

name = “No name yet”;

age = 0;

if (initialWeight < 0) {

System.out.println(“Error: Negative weight.”);

System.exit(0);

} else

weight = initialWeight;

}

public void setWeight(double newWeight) {

if (newWeight < 0) {

System.out.println(“Error: Negative weight.”);

System.exit(0);

} else

weight = newWeight;

}

public PetRecord() {

name = “No name yet.”;

age = 0;

weight = 0;

}

public String getName() {

return name;

}

public int getAge() {

return age;

}

public double getWeight() {

return weight;

}

public void print() {

System.out.println(“Name: ” + name + “nAge: ” + age +” years” + “nWeight: ” + weight + ” pounds”);

}

}

//end of PetRecord class

//start of DogRecord class

public class DogRecord extends PetRecord

{

   private boolean hasLongHair;

  

   public DogRecord()

   {

  

   }

  

   public DogRecord(String initialName, doubleinitialWeight, int intitialAge, boolean hasLongHair)

   {

   super(initialName, intitialAge, initialWeight);

   this.hasLongHair = hasLongHair;

   }

  

   public void setHasLongHair(boolean hasLongHair)

   {

   hasLongHair = hasLongHair;

   }

  

   public boolean getHasLongHair()

   {

   return hasLongHair;

   }

  

   public void print()

   {

   super.print();

   System.out.println(“hasLongHair: ” +hasLongHair);

   }

}

//end of DogRecord class

//start of CatRecord class

public class CatRecord extends PetRecord

{

   private boolean hasLongHair;

  

   public CatRecord()

   {

  

   }

  

   public CatRecord(String initialName, doubleinitialWeight, int intitialAge, boolean hasLongHair)

   {

   super(initialName, intitialAge, initialWeight);

   this.hasLongHair = hasLongHair;

   }

  

   public void sethasLongHair(boolean hasLongHair)

   {

   hasLongHair = hasLongHair;

   }

  

   public boolean gethasLongHair()

   {

   return hasLongHair;

   }

  

   public void print()

   {

   super.print();

   System.out.println(“hasLongHair: ” +hasLongHair);

   }

  

}

//end of CatRecord class

//start of BirdRecord class

public class BirdRecord extends PetRecord

{

   private int numFeathers;

  

   public BirdRecord()

   {

  

   }

  

   public BirdRecord(String initialName, doubleinitialWeight, int intitialAge, int numFeathers)

   {

   super(initialName, intitialAge, initialWeight);

   this.numFeathers = numFeathers;

   }

  

   public void setnumFeathers(int numFeathers)

   {

   numFeathers = numFeathers;

   }

  

   public int getnumFeathers()

   {

   return numFeathers;

   }

  

   public void print()

   {

   super.print();

System.out.println(“numFeathers: ” + numFeathers);

   }

}

//end of BirdRecord class

//Start of PetRecordMain (main) class

public class PetRecordMain {

public static void main(String[] args) {

PetRecord[] petArr = new PetRecord[3];

petArr[0] = new DogRecord(“Sparky”, 30.4, 6, true);

petArr[1] = new CatRecord(“Kitty”, 10.3, 8, true);

petArr[2] = new BirdRecord(“Tweety”, 3.4, 5, 56);

petArr[0].print();

System.out.println();

petArr[1].print();

System.out.println();

petArr[2].print();

System.out.println();

}

}

//end of PetRecordMain class

Expert Answer


Answer to Draw a UML class diagram for PetRecord, CatRecord, DogRecord and BirdRecord in the following code: //start of PetRecord …

OR