Answered step by step
Verified Expert Solution
Link Copied!

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 I/O 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 0.0 to 1.0
int painLevel
Ranges from 1 to 10
Constructor:
Pet(String name, double health, int painLevel)
health
If health passed in is greater than 1.0, set health to 1.0
If health passed in is less than 0.0, set health to 0.0
painLevel
If painLevel passed in is greater than 10, set pain level to 10
If painLevel passed in is less than 1, set pain level to 1
Methods:
getters for all instance fields, which should be camelCase with the variable name, e.g. 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 5 prints the message in UPPERCASE
boolean equals(Object 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 1.0
Sets painLevel to 1
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:
Dog(String name, double health, int painLevel, double droolRate)
droolRate - If droolRate is less than or equal to zero, set drool rate to 0.5
Dog(String name, double health, int painLevel)
Default droolRate is 5.0
Methods:
getters for all instance fields, which should be camelCase with the variable name, e.g. 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 3.5, the minutes for treatment is (painLevel*2)/health
if droolRate is in between 3.5 and 7.5 inclusive, the minutes for treatment is painLevel/health
if droolRate is greater than 7.5, the minutes for treatment is painLevel/(health*2)
void speak():
Calls parent method
Prints bark number of times of the painLevel
e.g.: if painLevel =3
Prints bark bark bark
ALL UPPERCASE if painLevel is greater than 5, not inclusive
boolean equals(Object o):
Uses the equals() method in Pet as part of the decision-making 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:
Cat(String name, double health, int painLevel, int miceCaught)
miceCaught
If miceCaught passed in is less than 0, set miceCaught to 0
Cat(String name, double health, int painLevel)
Default miceCaught is 0
Methods:
getters for all instance fields, which should be camelCase with the variable name, e.g. 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 4, the minutes for treatment is equal to (painLevel *2)/health
if miceCaught is in between 4 and 7 inclusive the minutes for treatment equals painLevel/health
if miceCaught is greater than 7, the minutes for treatment equals painLevel/(health*2)
void speak():
Calls parent method
Prints meow number of times of miceCaught
Eg: if miceCaught =3
Print meow meow meow
ALL UPPERCASE if painLevel is greater than 5, not inclusive
boolean equals(Object o):
Uses the equals() method in Pet as part of the decision-making 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!
InvalidPetException(String s) has message s
Clinic.java
This is a class representing the vet clinic.
Variables
File patientFile
File with patient information
int day
Constructors
Clinic(File file)
File that contains patient info - assign to patientFile
Name
Type of pet (includes pet info)
Appointment Info
timeIn(military time)
health(before Treatment)
painLevel(before Treatment)
TimeOut(military time)
TimeOut(military time)
Day initialized to 1
Clinic(String fileName)
String include

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_2

Step: 3

blur-text-image_3

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part I Lnai 8724

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448475, 978-3662448472

More Books

Students also viewed these Databases questions