ANSWER:
( 1 ).
public class Name{ //header declaration for the class Name
/*
Declare all necessary fields.
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; // person's first name called firstName
String lastName; // person's last name called lastName
char middleInitial; // person's middle initial called middleInitial
}
==========================================================
( 2 )
/*
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.
Special note:
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.
Hope this helps!