Problem Statement
Create a class NameSort that contains a method newList that takes a String[] list of names as input and returns the new sorted list as a String[]. The last name of a customer is defined to be the part of the name following the last space character, or the whole name if it has no space characters. The last name of "Bob E Jones" is "Jones". The last name of "Madona" is "Madona".
The names in the new sorted list should retain the same capitalization as they had in the original list.
Definition
- Class:
- NameSort
- Method:
- newList
- Parameters:
- String[]
- Returns:
- String[]
- Method signature:
- String[] newList(String[] list)
- (be sure your method is public)
Constraints
- list will contain between 1 and 50 elements, inclusive
- each element of list will contain between 1 and 20 characters, inclusive
- each character in each element of list will be a space, ' ', or a letter ('A'-'Z' or 'a'-'z')
- no element of list will contain leading or trailing spaces
- no element of list will contain two or more adjacent spaces
Examples
{"Tom Jones","ADAMS","BOB ADAMS", "Tom Jones","STEVE jONeS"}Returns: { "BOB ADAMS", "ADAMS", "STEVE jONeS", "Tom Jones", "Tom Jones" }ADAMS comes before JONES. The ADAMS names are listed in reverse order as compared to the original list. Likewise for the JONES names.{"C A R Hoare","Kenny G", "A DeForest Hoar","Kenny Gee"}Returns: { "Kenny G", "Kenny Gee", "A DeForest Hoar", "C A R Hoare" }No two of these names have the same last name. So the final list is the case-insensitive alphabetically ordered by last name version of the original.{"Trudy","Trudy","TRUDY"}Returns: { "TRUDY", "Trudy", "Trudy" }All three have the same last name. So they are sorted by importance, which corresponds to the reverse order as compared with the original list.{"tIm JoNeS", "Tim Jones", "tom JoNes", "tim joness", "tiM joneS"}Returns: { "tiM joneS", "tom JoNes", "Tim Jones", "tIm JoNeS", "tim joness" }{"Alan","aLan","alAn","alaN","ALan","AlAn","AlaN","aLAn","aLaN","alAN"}Returns: { "alAN", "aLaN", "aLAn", "AlaN", "AlAn", "ALan", "alaN", "alAn", "aLan", "Alan" }{"Al Thompson","Bob Johnson", "John Thompson", "John D Thompson","Bob D Johnson"}Returns: { "Bob D Johnson", "Bob Johnson", "John D Thompson", "John Thompson", "Al Thompson" }