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

Consider the following detailed inheritance hierarchy diagram The person constru

ID: 3839928 • Letter: C

Question

Consider the following detailed inheritance hierarchy diagram The person constructor has two string parameters: a first name and a last name. the constructor initializes e-mail address to the first letter of the first name followed by the first five letters of the last name followed @jc.com. If the last name has fewer than five letters, the e-mail address will be the first letter of the first name followed by the entire last name followed by @jc.com. Examples: Name Email address Jane Smith JSmith@jc.com John Morris JMorri@jc.com Mary Key MKey@jc.com Implement the Person constructor.

Explanation / Answer

The constructor function is as follows:

person(String firstname, String lastname){
     char[] charArray;
     int i;
     charArray = new char[15];
     myFirstName = firstname;
     myLastName = lastname;
     charArray[0] = firstname.charAt(0);    //First character is the first letter of firstname
     for (i=1; i<6; && i<lastname.length(); i++) //This ensures either 5 letters from last or if the length of lastname
         charArray[i] = lastname.charAt(i);       // is less than 5 then all the lastname will be added
     myEmailAddress = new String(charArray);
     myEmailAddress = myEmailAddress + "@jc.com";
   
}