APT: ClientsList

Class

public class ClientsList { public String[] dataCleanup(String[] names) { // fill in code here } }

Problem Statement

Your company has just undergone some software upgrades, and you will now be storing all of the names of your clients in a new database. Unfortunately, your existing data is inconsistent, and cannot be imported as it is. You have been tasked with writing a program to cleanse the data.

You are given a String[], names, which is a list of the names of all of your existing clients. Some of the names are in "First Last" format, while the rest are in "Last, First" format. You are to return a String[] with all of the names in "First Last" format, sorted by last name, then by first name.

Constraints

Examples

  1.     	
    {"Joe Smith", "Brown, Sam", "Miller, Judi"}
    Returns: { "Sam Brown",  "Judi Miller",  "Joe Smith" }
    
    
    The last names, in order, are Brown, Miller, Smith. We rearrange each name to be in the proper format also.

  2. 
    {"Campbell, Phil", "John Campbell", "Young, Warren"}
    
    Returns: { "John Campbell",  "Phil Campbell",  "Warren Young" }
    
    
    Notice here how we sort by first name when the last names are the same.

  3. 
    {"Kelly, Anthony", "Kelly Anthony", "Thompson, Jack"}
    Returns: { "Kelly Anthony",  "Anthony Kelly",  "Jack Thompson" }
    
    
    Be careful to properly identify first name versus last name!

  4. 
    {"Trevor Alvarez", "Jackson, Walter", "Mandi Stuart",
     "Martin, Michael", "Peters, Tammy", "Richard Belmont",
     "Carl Thomas", "Ashton, Roger", "Jamie Martin"}
    Returns: 
    {
     "Trevor Alvarez",
     "Roger Ashton",
     "Richard Belmont",
     "Walter Jackson",
     "Jamie Martin",
     "Michael Martin",
     "Tammy Peters",
     "Mandi Stuart",
     "Carl Thomas" }
    
    
  5. 
    {"Banks, Cody", "Cody Banks", "Tod Wilson"}
    
    Returns: { "Cody Banks",  "Cody Banks",  "Tod Wilson" }
    
    
    Notice that two identical names can appear in the list.

  6. 
    {"Mill, Steve", "Miller, Jane"}
    
    Returns: { "Steve Mill",  "Jane Miller" }
    
    
    Notice that shorter names precede longer names alphabetically when the shorter name is a substring of the longer.