Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago