Answer to Question #238788 in Java | JSP | JSF for Zia

Question #238788

Design and develop an algorithm, function, method, utility, command or component that sorts a multi-column contact list (contain last name, first name, middle name). You may use any appropriate data structure of choice to hold your data.


Implement your solution as part of a program (written in JAVA) that displays list, before sorted, after sorted. Refer to the Sample Unsorted Input Data and the Sample Sorted Output Data below to see how the list be transformed by the sort process.


The output should be ordered by Last Name. First Name must be ordered within Last Name and the Middle Name should be ordered within First Name. All the sorting be performed in ascending order.


If use a pre-existing algorithm, identify Library, OS, individual, etc. give full attribution to source.


Sample Unsorted Input Data:

Smith, John Vince

Doe, Jane Marie

Doe, Sally Mae

Smith, Robert Anthony

Doe, Sally Maria

Sample Sorted Output Data:

Doe, Jane Marie

Doe, Sally Mae

Doe, Sally Maria

Smith, John Vince

Smith, Robert Anthony


1
Expert's answer
2021-09-18T14:07:43-0400
import java.util.Arrays;  
import java.util.Scanner;
public class Main 
{  
public static void main(String args[])   
{ 
    Scanner in=new Scanner(System.in);
    int n;
    System.out.println("Enter number of people: ");
    n=in.nextInt();
    String [] names=new String [n];
    System.out.println("Enter "+n+" names: ");
    for(int i=0;i<n;i++){
        names[i]=in.next();
    }
    Arrays.sort(names);  
  
    System.out.println(Arrays.toString(names));  
}  
} 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS