Problem Statement
Create a class WhatSort that contains method sortType that is given a
- NAW -- name was the primary, age secondary, weight the final field
- NWA -- name was the primary, weight secondary, age final
- ANW -- age was primary, name was secondary, weight final
- AWN -- age was primary, weight was secondary, name final
- WAN -- weight primary, age secondary, name final
- WNA -- weight primary, name secondary, age final
- IND -- indeterminate: more than one of the above is possible
- NOT -- none of the above sorting methods was used
Definition
- Class:
- WhatSort
- Method:
- sortType
- Parameters:
- String[], int[], int[]
- Returns:
- String
- Method signature:
- String sortType(String[] name, int[] age, int[] wt)
- (be sure your method is public)
Constraints
- name will contain between 1 and 50 elements inclusive
- age and wt will contain the same number of elements as name
- each element in name will contain between 1 and 50 characters inclusive
- each character in each element of name will contain only uppercase letters 'A'-'Z'
- each element of age and wt will be between 1 and 300 inclusive
Examples
{"BOB","BOB","DAVE","JOE"}
{22, 35, 35, 30}
{122, 122, 195, 200}
Returns: "IND"
The ages are not in ascending order and the weights are not in descending order so the primary field must be name. The tie between the 2 BOB's could have been broken by increasing age, leaving the weight field as final. But it is also possible that the weight field was secondary, leaving the 2 BOB tie to be resolved by age. So we cannot determine which of those two sorts was used.
{"BOB","BOB","DAVE","DAVE"}
{22, 35, 35, 30}
{122, 122, 195, 200}
Returns: "NOT"
The ages are not in ascending order and the weights are not in descending order so the primary field must be name. There is a tie between the 2 BOB's and between the 2 DAVE's. If the secondary field were age, then the DAVE's would have been placed in the other order. That is also true if weight were the secondary field. So none of the sorts could have been used.
{"BOB","BOB","DAVE","DAVE"}
{22, 35, 35, 30}
{122, 122, 195, 190}
Returns: "NWA"
The ages are not in ascending order and the weights are not in descending order so the primary field must be name. Weight as secondary field properly orders the 2 DAVE's and leaves the ordering of the 2 BOB's up to the final field.
{"A","A","A","AA","A"}
{3,8,2,4,9}
{175, 173, 160, 160, 122}
Returns: "IND"
{"A","A","AAA","AA","A"}
{3,8,2,4,9}
{175, 173, 160, 160, 122}
Returns: "WAN"
{"A","A","A","B","B","C"}
{48,48,72,70,71,75}
{10,10,9,9,8,8}
Returns: "IND"
{"A","B","A","B","B","C"}
{48,48,72,70,71,75}
{10,10,9,9,8,8}
Returns: "WNA"
{"D","D","D","D","D","D"}
{1,2,3,4,5,6}
{6,5,4,1,3,2}
Returns: "IND"
{"JEREMIAH","BOB","BOB"}
{7,2,3}
{200,180,180}
Returns: "IND"
{"JEREMIAH","JEREMIAH","YAHOUDI"}
{7,12,3}
{200,220,220}
Returns: "NAW"
{"A","B","C","C","A","A","A"}
{1,1,1,1,2,2,2}
{200,230,240,230,300,300,198}
Returns: "ANW"
{"DAVE","EDGAR","AL","AL","BILL", "BILL","ABLE","AL","JIM","JIM"}
{20,21,22,23,23,23,23,24,25,25}
{150,180,200,212,212,200,100,223,229,229}
Returns: "AWN"
{"DAVE","EDGAR","ALL","AL","BILL", "BILL","ABLE","AL","JIM","JIM"}
{20,21,22,23,23,23,23,25,25,25}
{150,180,200,212,212,200,100,223,229,229}
Returns: "NOT"
{"DAVE","EDGAR","AL","AL","AL", "AL","ABLE","AL","JIM","JIM"}
{20,21,22,23,23,23,23,24,25,25}
{150,180,212,212,212,212,201,223,229,229}
Returns: "AWN"
{"A","B","C","C","A","A","A"}
{1,1,1,1,2,2,2}
{260,250,240,240,300,300,198}
Returns: "IND"
{"A","B","C","C","A","A","A"}
{1,1,1,1,1,1,1}
{200,230,240,230,300,300,198}
Returns: "NOT"
{"JEREMIAHJONES","JEREMIAH","YAHOUDI"}
{7,12,3}
{200,220,220}
Returns: "NOT"
{"JEREMIAH","JEREMIAH","YAHOUDI"}
{7,12,3}
{220,220,220}
Returns: "IND"
{"A","B","A","A","B","C"}
{48,48,72,70,71,75}
{10,10,9,9,8,8}
Returns: "NOT"
{"A","B","A","B","B","C","C"}
{48,48,72,70,71,75,75}
{10,10,9,9,8,8,8}
Returns: "WNA"
{ "BOB", "BOB", "DAVE", "DAVE" }
{ 22, 35, 35, 30 }
{ 122, 122, 195, 200 }
Returns: "NOT"
{ "BOB", "BOB", "DAVE", "JOE" }
{ 22, 35, 35, 30 }
{ 122, 122, 195, 200 }
Returns: "IND"
{ "BOB", "BOB", "DAVE", "DAVE" }
{ 22, 35, 35, 30 }
{ 122, 122, 195, 190 }
Returns: "NWA"
{ "DAVE", "DAVE", "BOB", "DAVE" }
{ 25, 30, 30, 25 }
{ 200, 200, 180, 180 }
Returns: "WNA"
{ "BOB", "BOB" }
{ 20, 20 }
{ 100, 100 }
Returns: "IND"
{ "ZZZ", "AAA", "AAA" }
{ 1, 2, 3 }
{ 66, 55, 44 }
Returns: "IND"
{ "BOB", "BOB" }
{ 200, 40 }
{ 2, 2 }
Returns: "NOT"