165k views
5 votes
Public String getNormalOrder() Returns the person's name in normal order, with the first name followed by the middle initial and last name. For example, if the first name is "John", the middle initial is 'Q', and the last name is "Public", this method returns "John Q. Public". public String getReverseOrder() Returns the person's name in reverse order, with the last name preceding the first name and middle initial. For example, if the first name is "John", the middle initial is 'Q', and the last name is "Public", this method returns "Public, John Q.".

You don't need to write the class header or declare the fields; assume that this is already done for you. Just write your two methods'

1 Answer

2 votes

Answer:

public static String getNormalOrder(String fname, String lname, String init){

return fname+" "+init+" "+lname;

}

public static String getReversedOrder(String fname, String lname, String init){

return lname+" "+lname+" "+init;

}

Step-by-step explanation:

In java programming language, the two methods are written above

The methods receive as parameters the fname, lname and init representing first name, last name and initials respectively

The first method returns a concatenated string in the correct order as specified by the question

The second method also returns the concatenated string as specified

See a complete code below where all variables are declared and the methods are called

public class ReversingNames {

public static void main(String[] args) {

String fname = "John";

String lname = "Public";

String init = "Q";

//Call getNormalOder

System.out.println(getNormalOrder(fname,lname,init));

//Call getReversedOrder

System.out.println(getReversedOrder(fname,lname,init));

}

public static String getNormalOrder(String fname, String lname, String init){

return fname+" "+init+" "+lname;

}

public static String getReversedOrder(String fname, String lname, String init){

return lname+" "+lname+" "+init;

}

}

User Fszlin
by
6.3k points