Problem Statement
- "ASCENDING mean" if the numbers are in increasing order and there are no repeated values,
- "DESCENDING mean" if the numbers are in decreasing order and there are no repeated values,
- "NONASCENDING freq" if the numbers are in decreasing order and contain repeated values,
- "NONDESCENDING freq" if the numbers are in increasing order and contain repeated values,
- or "NOTHING" if the numbers are none of the above.
and freq is the number of times the most frequently occurring value occurred in the sequence.
Neither numerator nor denominator should have any leading zeros. For example (quotes for clarity):
values = {1,2,4,11} return "ASCENDING 9/2" since the average is 18/4 = 9/2 values = {1,2,2,2,3,4} return "NONDESCENDING 3" since 2 occurred 3 times values = {6,5,1} return "DESCENDING 4/1" since the average is 12/3 = 4/1 values = {5,5,4,4,1} return "NONASCENDING 2" since 5 occurred twice values = {1,2,3,4,1} return "NOTHING" since no other choice is possible
Definition
- Class:
- Ordered
- Method:
- getType
- Parameters:
- int[]
- Returns:
- String
- Method signature:
- String getType(int[] values)
- (be sure your method is public)
Notes
- Be sure that you spell everything correctly.
Constraints
- values must contain between 2 and 50 elements inclusive
- At least 2 elements of values must be distinct
- Each element of values must be between 1 and 1000 inclusive
Examples
{1,2,4,11}
Returns: "ASCENDING 9/2"
Increasing order with no repeats
{1,2,2,2,3,4}
Returns: "NONDESCENDING 3"
Increasing order but the 2 is repeated 3 times
{6,5,1}
Returns: "DESCENDING 4/1"
Decreasing order with no repeats
{5,5,4,4,1}
Returns: "NONASCENDING 2"
Decreasing order but there are repeats
{1,2,3,4,1}
Returns: "NOTHING"
The sequence increases at first but decreases at the end
{1000,999,998}
Returns: "DESCENDING 999/1"
Decreasing with no repeats
{999,1000,1000,1000,1000,1000}
Returns: "NONDESCENDING 5"
{1,1000,1,1000,1,1000}
Returns: "NOTHING"
{1,2,3,4,5,6,7,8,9,10, 11,12,13,14,15,16,17,18,19,20, 21,22,23,24,25,26,27,28,29,30, 31,32,33,34,35,36,37,38,39,40, 41,42,43,44,45,46,47,48,49,50}
Returns: "ASCENDING 51/2"
{1,2,3,4,5,6,7,8,9,10, 11,12,13,14,15,16,17,18,19,20, 21,22,23,24,25,26,27,28,29,30, 31,32,33,34,35,36,37,38,39,40, 41,42,43,44,45,46,47,48,49,49}
Returns: "NONDESCENDING 2"
{1,2,3,4,5,6,7,8,9,10, 11,12,13,14,15,16,17,18,19,20, 21,22,23,24,25,26,27,28,29,30, 31,32,33,34,35,36,37,38,39,40, 41,42,43,44,45,46,47,48,49,51}
Returns: "ASCENDING 638/25"
{1,2,3,4,5,6,7,8,9,10, 11,12,13,14,15,16,17,18,19,20, 21,22,23,24,24,26,27,28,29,30, 31,32,33,34,35,36,37,38,39,40, 41,42,43,44,45,46,47,48,49,50}
Returns: "NONDESCENDING 2"
{1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, 1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, 1000,1000,1000,1000,999,1000,1000,1000,1000,1000, 1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, 1000,1000,1000,1000,1000,1000,1000,1000,1000,1000}
Returns: "NOTHING"
{1000,999,998,997,996,995,994,993,992,991,990, 989,988,987,986,985,984,983,982,981,980, 979,978,977,976,975,974,973,972,971,970, 969,968,967,966,965,964,963,962,961,960, 959,958,957,956,955,954,953,952,951}
Returns: "DESCENDING 1951/2"
{1,1,2,2,3,3,4,4,5,5,6,6,7,7,8}
Returns: "NONDESCENDING 2"
{1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,7}
Returns: "NOTHING"
{22,132,234,123,523,523,532,12,43,234,234,243}
Returns: "NOTHING"
{1000,1000,999}
Returns: "NONASCENDING 2"
{2,2,1}
Returns: "NONASCENDING 2"
{1,2,2}
Returns: "NONDESCENDING 2"
{ 3, 2, 1 }
Returns: "DESCENDING 2/1"
{ 1, 2, 3, 6 }
Returns: "ASCENDING 3/1"
{ 1, 1000 }
Returns: "ASCENDING 1001/2"
{ 1, 2, 2, 3, 3, 3, 4, 4 }
Returns: "NONDESCENDING 3"
{ 1, 2, 3, 4, 5 }
Returns: "ASCENDING 3/1"
{ 1, 2, 3, 4 }
Returns: "ASCENDING 5/2"
{ 1, 2, 2 }
Returns: "NONDESCENDING 2"