- Objective: To implement a
PetsOwnerwhich manipulates compositePetobjects. - Description Pets are Animals that can be either Dog or Cat. An Owner can have multiple Pets.
- Ensure each of the test cases in the class Pet successfully passes upon completion of each of the method stubs in the class PetTest.
- Constructors
Pet()Pet(String)Pet(int)Pet(String, int)
String getName()Integer getAge()void setOwner(PetOwner owner)PetOwner getOwner()
- Constructors
- To create a programmatic representation of a
Pet, begin by declaring an instance variable for each of the following properties:String name- a collection of characters, representative of a name.
Integer age- an integer, representative of an age in years.
PetOwner owner- the owner of this
Pet.
- the owner of this
- Define a
Petconstructor whose parameters are used to initialize its instance variables. - A
Petcan be constructed in 4 ways.Pet()- Upon nullary construction, pet has
ageof 0 andnameof "".
- Upon nullary construction, pet has
Pet(String)- Upon construction,
namefield should be set to respective parameter value, pet has default age of 0.
- Upon construction,
Pet(int)- Upon construction,
agefield should be set to respective parameter value, pet has default name of "".
- Upon construction,
Pet(String, int)nameandagevariables should set to respective parameter values.
- Understand that instance variables are not directly exposed outside of the class. We use getter and setter methods to retrieve and assign values, respectively, to gatekeep their contents.
- Define a getter and setter for each of the instance variables declared in the
Petclass.String getName()Integer getAge()void setOwner()PetOwner getOwner()
- Understand that
Petis the parent class.CatandDoginherit fromPet, and implement theAnimalinterface. - Cat
- Dog
-
Ensure each of the test cases in the class PetOwner successfully passes upon completion of each of the method stubs in the class PetOwner.
PetOwner(String name, Pet... pets)void addPet(Pet pet)void removePet(Pet pet)Boolean isOwnerOf(Pet pet)Integer getYoungestPetAge()Integer getOldestPetAge()Double getAveragePetAge()Integer getNumberOfPets()String getName()Pet[] getPets()