Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem Description Hello! Please make sure to read all parts of this document carefully. In this assignment, you will be applying your knowledge of abstract
Problem Description
Hello! Please make sure to read all parts of this document carefully.
In this assignment, you will be applying your knowledge of abstract classes, inheritance, polymorphism, file IO and exceptions. For this homework, you will be simulating a veterinary clinic. You will create a Pet.java, Dog.java, Cat.java, InvalidPetException.java, and a Clinic.java file; the Clinic.java file will treat and keep a record of the Pet patients it receives!
Solution Description
Create files Pet.java, Dog.java, Cat.java, InvalidPetException.java and Clinic.java. Each file will have instance fields, methods, and constructors.
Pet.java
This class represents any pet that would seek consultation from the clinic.
Variables:
String name
double health
A percentage value ranging from to
int painLevel
Ranges from to
Constructor:
PetString name, double health, int painLevel
health
If health passed in is greater than set health to
If health passed in is less than set health to
painLevel
If painLevel passed in is greater than set pain level to
If painLevel passed in is less than set pain level to
Methods:
getters for all instance fields, which should be camelCase with the variable name, eg a variable named hello should have a getter getHello
int treat:
Should be an abstract method that returns the time taken in minutes to treat the pet
void speak:
This method prints Hello My name is with the pets name
If painLevel is greater than prints the message in UPPERCASE
boolean equalsObject o:
Two Pet objects are equal if their names are the same
Note: You can assume you will not encounter two pets with the same name
heal:
Should be protected to prevent access by external classes
Sets health to
Sets painLevel to
Dog.java
Since a Dog is also a Pet, this class must inherit from parent class Pet. This class is concrete.
Variables:
double droolRate
Constructors:
DogString name, double health, int painLevel, double droolRate
droolRate If droolRate is less than or equal to zero, set drool rate to
DogString name, double health, int painLevel
Default droolRate is
Methods:
getters for all instance fields, which should be camelCase with the variable name, eg a variable named hello should have a getter getHello
int treat:
Should heal
Returns the time taken in minutes to treat the pet. Round values up
if droolRate is less than the minutes for treatment is painLevelhealth
if droolRate is in between and inclusive, the minutes for treatment is painLevelhealth
if droolRate is greater than the minutes for treatment is painLevelhealth
void speak:
Calls parent method
Prints bark number of times of the painLevel
eg: if painLevel
Prints bark bark bark
ALL UPPERCASE if painLevel is greater than not inclusive
boolean equalsObject o:
Uses the equals method in Pet as part of the decisionmaking with the additional condition of droolRate being the same
Cat.java
Since a Cat is also a Pet, this class must inherit from parent class Pet. This class is concrete.
Variables:
int miceCaught
Constructors:
CatString name, double health, int painLevel, int miceCaught
miceCaught
If miceCaught passed in is less than set miceCaught to
CatString name, double health, int painLevel
Default miceCaught is
Methods:
getters for all instance fields, which should be camelCase with the variable name, eg a variable named hello should have a getter getHello
int treat:
Should heal
Returns the time taken in minutes to treat the pet. Round all values up
if number of miceCaught is less than the minutes for treatment is equal to painLevel health
if miceCaught is in between and inclusive the minutes for treatment equals painLevelhealth
if miceCaught is greater than the minutes for treatment equals painLevelhealth
void speak:
Calls parent method
Prints meow number of times of miceCaught
Eg: if miceCaught
Print meow meow meow
ALL UPPERCASE if painLevel is greater than not inclusive
boolean equalsObject o:
Uses the equals method in Pet as part of the decisionmaking with the additional condition of miceCaught being the same
InvalidPetException.java
An unchecked exception with two constructors
Constructors
InvalidPetException has message Your pet is invalid!
InvalidPetExceptionString s has message s
Clinic.java
This is a class representing the vet clinic.
Variables
File patientFile
File with patient information
int day
Constructors
ClinicFile file
File that contains patient info assign to patientFile
Name
Type of pet includes pet info
Appointment Info
timeInmilitary time
healthbefore Treatment
painLevelbefore Treatment
TimeOutmilitary time
TimeOutmilitary time
Day initialized to
ClinicString fileName
String include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started