Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need some help with an Inheritance problem in Java* Create three classes... Ch

ID: 3888331 • Letter: I

Question

I need some help with an Inheritance problem in Java*

Create three classes... Child, Adult, and ChildAdult. For these classes, all fields should be defined and all have an accessor and a mutator(getter/setter) defined

*For the Child class, it should have a field named childID that records the number used for this child(make it a string) with accessor / mutator(as stated before).... make a constructor for it that has a string parameter that is used to get the childID for the child... lastly make a method string that formats the ID by returning the String "Child: " + childID

*For the Adult class, make a field called moneyEarned(double) that records the money made hourly by the adult, also with a accessor and mutator(as stated before)... Also make a constructor that has single double parameter that is used to get the moneyEarned

*For the ChildAdult class, have it extend Child and have a field type of Adult.... it should have ...

-a field recording the childID (make it a string)

-a field type Adult named work that will record the money earned

-a field type called freeTime(integer) that holds the hours they are free that term.

-a constructor with a string parameter that uses the childID, a double parameter that is used to set the money earned and an integer parameter that used to set the number of hours they worked

-Methods for childID and moneyEarned should be able to be accessed and mutated

- a method string childID() that returns the String "Child: " + childID + "and makes " +moneyEarned+ " for " +the number of hours worked + "hours"   /***[note: i am personally confused by this]***/

-a method for Child called getChildInstance() and have it return the instance of type Child that represents ChildAdult

-lastly, make a method Adult getAdultInstance() that returns the instance type of Adult representing ChildAdult (there should be a field for this)

Explanation / Answer

class Child{ String childID; public Child(String childID) { //Constructor with childID this.childID = childID; } public String getChildID() { //getter return childID; } public void setChildID(String childID) { //setter this.childID = childID; } public String childId() //method which returns "child:"+childID { return("child:"+childID); } Child getChildInstance(ChildAdult ca){ //incoming argument is ChildAdult, but returning instance of Child. return ca; } } class Adult{ double moneyEarned; public Adult(){ } public Adult(double moneyEarned) { //Constructor this.moneyEarned = moneyEarned; } public double getMoneyEarned() { //getter return moneyEarned; } public void setMoneyEarned(double moneyEarned) { //setter this.moneyEarned = moneyEarned; } Adult getAdultInstance(ChildAdult ca){ //incoming argument is ChildAdult, but returning instance of Adult (after extraction). Adult tempAdult = ca.adult; return tempAdult; } } class ChildAdult extends Child{ Adult adult; int freeTime; public ChildAdult(String childID, Adult adult, int freeTime) { // constructor super(childID); this.adult = adult; this.freeTime = freeTime; } //Actual Demonstration public static void main(String args[]) { Adult adult = new Adult(999.99); //Creating Adult object ChildAdult childAdult = new ChildAdult("Ch123",adult,12); //Creating ChildAdult obj with constructor(childID,adult,freeTime) System.out.println(childAdult.childID+" and makes "+childAdult.adult.getMoneyEarned()+" for "+childAdult.freeTime+" hours "); } }