Question: The primary objective is to explore inheritance, interfaces, and their integration while managing pets treated and boarded at an animal hospital. Class: Pet The class
The primary objective is to explore inheritance, interfaces, and their integration while managing pets treated and boarded at an animal hospital.
Class: Pet
The class should have the three private data members: petNameStringownerNameString and colorString along with one protected data member genderint representing male or female
Public methods:
Constructor: PetString petName, String ownerName, String color
String getPetName
String getOwnerName
String getColor
void setGenderint genderid
String getGender: Return the string equivalent of the gender, eg Male
String toString: Return the name, owners name, age, color, and gender
A Sample preferred return value by toString is as follows:
Spot owned by Mary.
Color: Black and White
Gender: Male
Interface: Boardable
This interface should contain the following public methods:
void setBoardStartint month, int day, int year;
void setBoardEndint month, int day, int year;
boolean boardingint month, int day, int year;
Refer to the Cat and Dog classes for implementing details. Note: Month ranges from to day ranges from to and year is a fourdigit number.
Class: Cat
This class extends the Pet class and implements the Boardable interface. It introduces a private data member, hairLength, and provides the following public methods:
Cat String name, String ownerName, String color, String hairLength:
Constructor for Cat object, invoking the superclass constructor.
String getHairLength: Retrieves the hair length of the cat.
String toString: Returns a detailed description of the cat, including the values from the Pet parent class.
To implement the Boardable interface, define new data members are added to store boarding start and end dates. The setBoardStart and setBoardEnd methods are implemented to set values for these dates, and a boarding method is provided to determine if the given date falls within the boarding period, returning true if it does, including cases where the date matches the start or end date.
A Sample preferred return value by toString is as follows:
CAT:
Tom owned by Bob.
Color: black
Sex: spayed
Hair: short
Class: Dog
This class should extend the Pet class and implement the Boardable interface. The Dog class should include a private string data member size in addition to inherited members from Pet.
Public methods provided should include:
Dog String name, String ownerName, String color, String size: Initialize size and calls super.
String getSize: Returns the size
String toString :Returns a String identifying the pet as Dog and providing a complete description, including values from the Pet parent class.
A Sample preferred return value by toString is as follows:
DOG:
Spot owned by Susan.
Color: white
Sex: spayed
Size: medium
Class: AnimalHospital
This class neither extends other classes nor implements interfaces. It utilizes existing classes.
Declare final const fields for:
HOSPITALNAME
MAXCAPACITY: Maximum number of animals the hospital can accommodate.
DEFAULTTREATMENTCOST: default cost for treatments.
ACCEPTEDANIMALCATEGORIES: Categories of animals the hospital accepts.
Public methods to be provided include:
AnimalHospitalString inputFile: Constructor takes a filename and read records for animals starting with CAT or DOG and creates Dog or Cat objects. It invokes the setBoardSrart and setBoardEnd methods during object creation.
void printPetInfoByNameString name: Searches for pets with the given given name, and print their information using toString
void printPetInfoByOwnerString name: Searches for pets owned by the given person and print their information using toString
void printPetsBoardingint month, int day, year: Searches for pets boarding at the specified time and print their information using toString
void printHospitalInfo: Displays hospital information.
Sample of input data file: pets.txt
PET
Spot
Mary
Black and White
Male
CAT
Spot
Bob
Black
Female
Short
DOG
Hipper
James
Dark Brown
Female
Large
END
Driver Program:
public static void mainString args
AnimalHospital hospital new AnimalHospitalpetstxt;
System.out.printlnAnimal Hospital Information:";
hospital. printHospitalInfo;
System.out.printlnPets Named Spot";
hospital.printPetInfoByNameSpot;
System.out.println;
System.out.printlnPets Owned by James";
hospital.printPetInfoByOwnerJames;
System.out.println;
System.out.printlnPets Currently Boarded";
hospital.printPetsBoarding;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
