This is the first part of a larger problem that creates a collection of classes
ID: 3721167 • Letter: T
Question
This is the first part of a larger problem that creates a collection of classes that supports record keeping for a livestock farm. In part 1, you will create three classes to keep health records on livestock.
Part ACreate a class called HealthNote
This class must have the following private data
date (Must be type Dat)
observations (a string)
This class must have the following methods
default constructor
constructor with parameters for the data
copy constructor (This is new to you. See note below.)
Create appropriate accessor and mutator methods to return and modify the private data.
setNote with parameters for the data
toString
Part B
Create a class called VaccinationNote
This class must have the following private data
date (Must be type Dat)
vaccination (a string)
This class must have the following methods
default constructor
constructor with parameters for the data
copy constructor (This is new to you. See note below.)
Create appropriate accessor and mutator methods to return and modify the private data.
setNote with parameters for the data
toString
Part C
Create a class called HealthRecord
This class must have the following private data
birth date (Must be type Dat)
weight (a double)
history (an ArrayList of HealthNote)
vaccinations (an ArrayList of VaccinationNote)
This class must have the following methods
default constructor
constructor with parameters for the data
copy constructor (This is new to you. See note below.)
Create appropriate accessor and mutator methods to return and modify the private data.
setRecord with parameters for the data
toString
addHealthNote (adds a new HealthNote to history)
addVaccinationNote (adds a new VaccinationNote to vaccinations)
Hints
Create a new directory for Project06.
Save a copy of the Dat class in the Project05 directory.
For the HealthRecord class, error check the weight. It can not be less than or equal to zero.
Creating a Copy ConstructorA copy constructor has a single parameter of the same type as the class. It copies the data from the object passed in.
The Fraction class does not have a copy constructor. However, one could be added as follows.
This constructor uses the class accessor methods to copy the data from an object to the newly created object.
When adding objects to ArrayLists in your tester programs, use copy constructors or instantiate anonymous objects as arguments to insure each element of the ArrayList points to a unique object location. See BillTester for an example of instantiating anonymous objects as arguments.
Follow this development process
Create the HealthNote class.
Create a tester program, HealthNoteTester to test all methods and constructors.
Create the VaccinationNote class.
Create a tester program, VaccinationNoteTester to test all methods and constructors.
Create the HealthRecord class.
Create a tester program, HealthRecordTester to test all methods and constructors.
Compile, execute, and test the testing program to be certain all methods work correctly.
As you may not be knowledgeable of animal health issues, here are some sample health notes and vaccinations.
Health Notes
Cow has hardware.
Foot and Mouth Disease (Quarantine herd. Report to Health Department)
Rabies (Quarantine animal. Report to Health Department)
Mastitis (Treat twice a day for one week. Discard milk during treatment and for two weeks after last treatment)
Abscess between toes of right front foot. (Cleaned, treated, and bandaged. If not better in three days, call back.)
Avian Flu (Quarantine flock. Report to Health Department)
Swine Flu (Quarantine herd. Report to Health Department)
Vaccinations
Brucellosis
Rabies
Eastern equine encephalitis
Distemper
Viral respiratory vaccine (IBR, BVD, PI3, BRSV)
Scours
Foot and Mouth Disease
Turn in
HealthNote class
HealthNoteTester
VaccinationNote class
VaccinationNoteTester
HealthRecord class
HealthRecordTester
Explanation / Answer
import java.util.ArrayList; import java.util.Date; //HealthNote class HealthNote { private Date date; private String observations; public HealthNote() { } public HealthNote(Date date, String observations) { this.date = date; this.observations = observations; } public HealthNote(HealthNote h) { setDate(h.getDate()); setObservations(h.getObservations()); } public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } public String getObservations() { return observations; } public void setObservations(String observations) { this.observations = observations; } public void setNote(Date d,String observations) { setDate(d); setObservations(observations); } @Override public String toString() { return "HealthNote{" + "date=" + date + ", observations='" + observations + ''' + '}'; } } //HealthNoteTester class HealthNoteTester { public static void main(String[] args) { HealthNote hn1=new HealthNote(); hn1.setDate(new Date()); hn1.setObservations("Cow has hardware."); System.out.println(hn1.toString()); HealthNote hn2=new HealthNote(new Date(),"Foot and Mouth Disease (Quarantine herd. Report to Health Department)"); System.out.println(hn2.toString()); HealthNote hn3=new HealthNote(hn2); System.out.println(hn3.toString()); System.out.println("date="+hn1.getDate()+"observations="+hn1.getObservations()); hn3.setNote(hn1.getDate(),hn1.getObservations()); System.out.println(hn3.toString()); } } //VaccinationNote class VaccinationNote { Date date; String vaccination; //defualt constructor public VaccinationNote(){} //parameterized constructor public VaccinationNote(Date date, String vaccination) { this.date = date; this.vaccination = vaccination; } public VaccinationNote(VaccinationNote v) { setDate(v.getDate()); setVaccination(v.getVaccination()); } public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } public String getVaccination() { return vaccination; } public void setVaccination(String vaccination) { this.vaccination = vaccination; } @Override public String toString() { return "VaccinationNote{" + "date=" + date + ", vaccination='" + vaccination + ''' + '}'; } public void setNote(Date d,String vaccination) { setDate(d); setVaccination(vaccination); } } class VaccinationNoteTester { public static void main(String[] args) { VaccinationNote v1=new VaccinationNote(); v1.setDate(new Date()); v1.setVaccination("Brucellosis"); System.out.println(v1); VaccinationNote v2=new VaccinationNote(new Date(),"Rabies"); System.out.println(v2.toString()); VaccinationNote v3=new VaccinationNote(v2); System.out.println(v3.toString()); v3.setNote(v1.getDate(),v1.getVaccination()); System.out.println(v3); } } class HealthRecord { private Date birthDate; private double weight; ArrayList history; ArrayList vaccinations; public HealthRecord(){} public HealthRecord(Date birthDate, double weight, ArrayList history, ArrayList vaccinations) { this.birthDate = birthDate; this.weight = weight; this.history = history; this.vaccinations = vaccinations; } public HealthRecord(HealthRecord h) { setBirthDate(h.getBirthDate()); setWeight(h.getWeight()); setVaccinations(h.getVaccinations()); setHistory(h.getHistory()); } public Date getBirthDate() { return birthDate; } public void setBirthDate(Date birthDate) { this.birthDate = birthDate; } public double getWeight() { return weight; } public void setWeight(double weight) { this.weight = weight; } public ArrayList getHistory() { return history; } public void setHistory(ArrayList history) { this.history = history; } public ArrayList getVaccinations() { return vaccinations; } public void setVaccinations(ArrayList vaccinations) { this.vaccinations = vaccinations; } @Override public String toString() { return "HealthRecord{" + "birthDate=" + birthDate + ", weight=" + weight + ", history=" + history + ", vaccinations=" + vaccinations + '}'; } public void setRecord(Date d, double weight, ArrayList h, ArrayList v) { setBirthDate(d); setWeight(weight); setHistory(h); setVaccinations(v); } public void addHealthNote(HealthNote h) { history.add(h); } public void addVaccinationNote(VaccinationNote v) { vaccinations.add(v); } } class HealthRecordTester { public static void main(String[] args) { HealthRecord h=new HealthRecord(); h.setWeight(54.7); h.setBirthDate(new Date()); ArrayList hns=new ArrayList(); HealthNote hn1=new HealthNote(new Date(),"Rabies (Quarantine animal. Report to Health Department)"); // hns.add(hn1); // hns.add(new HealthNote(hn1)); h.setHistory(hns); h.addHealthNote(new HealthNote(hn1)); ArrayList vns=new ArrayList(); VaccinationNote vn1=new VaccinationNote(new Date(),"Eastern equine encephalitis"); // vns.add(vn1); // vns.add(new VaccinationNote(vn1)); h.setVaccinations(vns); h.addVaccinationNote(new VaccinationNote(vn1)); System.out.println(h.toString()); System.out.println(h.getBirthDate()+" "+h.getWeight()+" "+h.getHistory()+" "+h.getVaccinations()); HealthRecord h2=new HealthRecord(new Date(),h.getWeight(),h.getHistory(),h.getVaccinations()); System.out.println(h2.toString()); HealthRecord h3=new HealthRecord(h2); System.out.println(h3.toString()); h3.setRecord(new Date(),70,hns,vns); System.out.println(h3.toString()); } }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.