Answer:
The codes for the problem are given below
Step-by-step explanation:
//Name class
public class Name
{
private String first,last,middle;
public Name(String first,String middle,String last)
{
this.first=first;
this.middle=middle;
this.last=last;
}
public String getNormalOrder()
{
return first+" "+middle+". "+last;
}
public String getReverseOrder()
{
return last+", "+first+" "+middle+".";
}
public String toString()
{
return first+" "+middle+" "+last;
}
public void setFirstName(String first)
{
this.first=first;
}
public void setMiddleName(String middle)
{
this.middle=middle;
}
public void setLastName(String last)
{
this.last=last;
}
}
//TestNameClass class
public class TestNameClass
{
public static void main(String[] args)
{
Name myname=new Name("John","K","Watson");
myname.setFirstName("John");
myname.setMiddleName("Q");
myname.setLastName("Public");
System.out.println("My name: ");
System.out.println(myname.getNormalOrder());
System.out.println(myname.getReverseOrder());
Name friend=new Name("Sherlock","P","Holmes");
System.out.println("Friend's name: ");
System.out.println(friend.getNormalOrder());
System.out.println(friend.getReverseOrder());
}
}