Question: Lab 19 Create classes CatRecord, DogRecord and BirdRecord that inherit from (extend) the PetRecord class located on Canvas. Add an integer variable numFeathers to BirdRecord,

Lab 19

Create classes CatRecord, DogRecord and BirdRecord that inherit from (extend) the

PetRecord class located on Canvas.

Add an integer variable numFeathers to BirdRecord, and a Boolean variable

hasLongHair to CatRecord and DogRecord. Create appropriate setter and getter

methods for each.

Also, create constructors that can set all of the values for a cat, dog or bird by

setting the values specific to that animal and also using super to call the constructor

for PetRecord.

Lab 20

Modify the PetRecord class by adding a print() method to it that prints all of the

information on a given pet (that is common to all types of pets).

Override this print function in CatRecord, DogRecord, and BirdRecord to print all of

the information for a cat, dog, or bird, including the information specific to that

species your new print function should use the super keyword to call the

PetRecord print function, then print the additional information.

PetRecord:

PetRecord.java /** Class for basic pet records: name, age, and weight. */ public class PetRecord { private String name; private int age;//in years private double weight;//in pounds

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; } }

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!