- Objective: To implement a
PetsOwner
which manipulates compositePet
objects.
- Ensure each of the test cases in the class Pet successfully passes upon completion of each of the method stubs in the class PetTest.
Pet()
Pet(String)
Pet(int)
Pet(String, int)
String getName()
Integer getAge()
void setOwner(PetOwner owner)
PetOwner getOwner()
- 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
Pet
constructor whose parameters are used to initialize its instance variables. - A
Pet
can be constructed in 4 ways.Pet()
- Upon nullary construction, pet has
age
of 0 andname
of "".
- Upon nullary construction, pet has
Pet(String)
- Upon construction,
name
field should be set to respective parameter value, pet has default age of 0.
- Upon construction,
Pet(int)
- Upon construction,
age
field should be set to respective parameter value, pet has default name of "".
- Upon construction,
Pet(String, int)
name
andage
variables should set to respective parameter values.
- Getters and Setters
- Define a getter and setter for each of the instance variables declared in the
Pet
class.String getName()
Integer getAge()
void setOwner()
PetOwner getOwner()
- Define a getter and setter for each of the instance variables declared in the
-
Dog
- Ensure
Dog
supports all methods of pet construction. - The mechanism by which a
Dog
speaks is by barking; ensure a dog'sspeak
method returnsbark
as a string.
- Ensure
-
Cat
- Ensure
Cat
supports all methods of pet construction. - The mechanism by which a
Cat
speaks is by meowing; ensure a cat'sspeak
method returnsmeow
as a string.
- Ensure
- 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 getYoungetPetAge()
Integer getOldestPetAge()
Double getAveragePetAge()
Integer getNumberOfPets()
String getName()
Pet[] getPets()