ANSWER:
<u>( 1 )</u><em><u>.</u></em>
<em><u /></em>
public class Name{ //header declaration for the class <em>Name</em>
/*
<em> Declare all necessary fields.</em>
The first and last names of the person are string variables.
Hence they are of type String.
The middle initial of the person is a single character.
Hence it is of type char.
*/
String firstName; // <em>person's first name called firstName</em>
String lastName; // <em>person's last name called lastName</em>
char middleInitial; // <em>person's middle initial called middleInitial</em>
}
==========================================================
<u>( 2 )</u>
/*
Method getNormalOrder() is declared as follows.
It returns the person's name in normal order with first name
followed by the middle initial and last name.
*/
public String getNormalOrder(){
// concatenate the firstName, middleInitial and lastName and return the
// result.
return this.firstName + " " + this.middleInitial + ". " + this.lastName;
}
/*
Method getReverseOrder() is declared as follows.
It returns the person's name with the last name
followed by the first name and middle initial.
*/
public String getReverseOrder(){
// concatenate the lastName, lastName and middleInitial and return the
// result.
return this.lastName + " " + this.firstName + " " + this.middleInitial + ".";
}
EXPLANATION:
The above code has been written in Java.
The code contains comments that explain every part of the code. Please go through the comments carefully for a better understanding of the code.
<em>Special note: </em>
i. Concatenation which means joining strings together, is done in Java using the + operator.
ii. The this keyword used in the two methods is optional. It is just used to reference to the instance variables - firstName, lastName and middleInitial - of the object.
<em>Hope this helps!</em>