A CareWorker works three days a week and has two properties:
An ElderlyPerson has 3 properties:
In a main program, when a CareWorker object is constructed, a reference to an ElderlyPerson object and a reference to a 3-element String array are passed as parameters eg
String[] days = {"Monday", "Thursday", "Saturday"};
ElderlyPerson e = new ElderlyPerson("Jane Briggs", 78, "Dementia");
CareWorker s = new CareWorker(e, days);
Create a new project called CareWorkerProject. Create the following 3 class files:
Using the information above, define private properties and design constructor methods for both the CareWorker and ElderlyPerson classes.
In the CareWorker class, create accessor methods for the 2 CareWorker properties.
In the ElderlyPerson class, create accessor methods for the 3 ElderlyPerson properties.
In the ElderlyPerson class, create a method called toString.
This method returns a String which contains all of an ElderlyPerson objects property data in 1 sentence eg:
Name: Martha Munroe; Age: 78; Illness: Dementia
In the ElderlyPerson class, create a method called birthday.
This method simply adds 1 to the current age of the ElderlyPerson.
In the CareWorker class, create a method called displayDays.
This method simply displays the three days that the CareWorker works.
In the CareWorker class, create a mutator method, setNewWorkDay(String dayToBeReplaced, String newDay)
This method searches the String array property for dayToBeReplaced and, if found, replaces it with newDay
In the CareWorker class, create a mutator method, setElderlyPerson(ElderlyPerson newPerson) which will replace the current elderly person with newPerson, as long as they don't have the same illness!
Now turn to the Main class. A program has been started:
public static void main(String[] args){
public ststic void main(String[] args){
String[] days = {"Friday", "Saturday", "Sunday"};
ElderlyPerson ep = new ElderlyPerson("Janny Jones", 104, "Deafness");
CareWorker c= new CareWorker(ep, days);
System.out.println(c.getElderlyPerson().toString());
c.getElderlyPerson().birthday();
//display all of the data associated with the ElderlyPerson object inside the CareWorker object!
System.out.println(c.getElderlyPerson().toString());
ElderlyPerson ethel = new ElderlyPerson("Ethel Xu", 95, "Deafness");
//attempt to change the ElderlyPerson inside the CareWorker object - this shouldn't work!
c.setElderlyPerson(ethel);
//hopefully no change!
System.out.println(c.getElderlyPerson().toString());
System.out.println(c.displayDays());
c.setNewWorkDay("Saturday", "Wednesday");
System.out.println(c.displayDays());
Code this Main program and see if it works as expected.