Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Draw a UML class diagram for PetRecord, CatRecord, DogRecord and BirdRecord in the following code: //start of PetRecord class public class PetRecord { private String

Draw a UML class diagram for PetRecord, CatRecord, DogRecord and BirdRecord 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" + " Weight: " + weight + " pounds");

}

public PetRecord(String initialName, int initialAge, double initialWeight) {

name = initialName;

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

System.out.println("Error: Negative age or weight.");

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 or weight.");

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 + " Age: " + age + " years" + " Weight: " + weight + " pounds");

}

}

//end of PetRecord class

//start of DogRecord class

public class DogRecord extends PetRecord

{

private boolean hasLongHair;

public DogRecord()

{

}

public DogRecord(String initialName, double initialWeight, 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, double initialWeight, 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, double initialWeight, 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 1 Lnai 6321

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215879X, 978-3642158797

More Books

Students also viewed these Databases questions