Question: DE! |. Create a New Class... named Person Declare the 4 fields named firstName, middleName, isMale and age Add a constructor with 4 parameters having
DE! |. Create a "New Class... named Person Declare the 4 fields named firstName, middleName, isMale and age Add a constructor with 4 parameters having the header public Person(String firstName, String middleName, Using this. in front of field variable names, assign firstName name above, BUT ater first removing leading/trailing HINT: Use extemal method calls to String trim() and boolean isMale, int age) and middieName fields equal to the parameters of the same spaces and making uppercase toUpperCasel) (in the most efficient order) on the parameters before assignment Initialize the isMale and age fields by also assigning them equal to the parameters of the same name and by prefixing this. for the fields Add an overloaded constructor with only 3 parameters and header public Person(String firstName, String middieName, boolean is Male) Initialize all fields in the same manner as the previous constructor, EXCEPT now initialize the age field to 0 e baby born at age 0) firstName field middleName field Add accessor named getFirstName to retum the value of Add accessor named getMiddleName to returm value of Add accessor named getAge to return the value of the age field Add accessor getGenderString to return a gender String with header public String getGenderString() if the isMale field is true, then returm "male - else return Temale HINT: Instead of the if-else block, this method could also be mplemented using the ternary conditional operator ? with only 1 line of code Add accessor getinitialsString to return first letter of first& middle names public String getinitials String) Only 1 statement to return the String concatenation (+ operator) of the 1 letter (using String substring) of the first & middle name fields Add mutator incrementAge to increment age field by 1 with header public void incrementAge() Only 1 statement using the unary operator++on the age field Add mutator changeFirstName to modify the firstName field with header public void changeFirstName(String firstName) if the firstName parameter is not nul Declare and initialize local variable newName by assigning it equal to the result of the parameter firstName after .trim and uppercase if the newName is NOT empty (using String isEmpty) Assign firstName fleld (using this.) equal to formatted Print "First name changed to: newName>" (use - else print "New first name does not contain any valid characters else print "New first name is nul Create a "New Class.. named Family Declare the 4 fields named sumame, husband, wife and child Add a constructor with 3 parameters having the header: public Family String surname, Person husband, Person wife) Using this, for surmame field, initialize field equal to result of parameter AFTER first removing leading/trailing spaces and making it uppercase HINT: Use external method calls trim() and toUpperCase)on the parameter before the assignment operation Initialize the husband and wife fields by also assigning them equal to the parameters of the same name and by prefiooing this. for the fields Initialize the child field to an appropriate value representing Add accessors named getSumame, getHusband, getWife & Add mutator haveChild to add a child to the family with the NO child public void haveChild(Person child) is born. parameter child Print first & middle names of chwd with proper spacing and " Assign the field child (using this.) equal to the input Add overloaded haveChild method with 3 parameters and the public void haveChild(String firstName, String middleWame, boolean isMale) Define local variable named baby of type Person AND initialize to a new Person object by calling Person constructor with 3 actual parameters is born. HINT: Must print the formatted values in the baby object Print first & middle names of baby with proper spacing and' and NOT the unformatted values passed in as the actual parameters Assign the field child equal to the new baby Add mutator haveFamilyBirthday to age all Family members by a public vold haveFamilyBirthday) husband &wife object AND "Wife is now cage> years old" for the wife HINT: Use external .getAge call to get the variable value Use external method calls to incrementAge for both the Print "Husband is now
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
