To change the method getRandomNumberArray, you can create an array and use a loop to generate random odd numbers within the desired range. For measureTime, create a new array and use a sorting algorithm to find the 10 smallest numbers. Add a nested private class to implement the BY_NAME comparator and use a suitable sorting algorithm to display friends sorted by name.
To change the method getRandomNumberArray to return an array of n uniformly random, odd numbers between 10 million and 500 million, you can follow these steps:
Create an empty array called randomArray
Use a loop to generate n random numbers
Check if each number is odd and falls within the desired range
If the number meets the criteria, add it to the randomArray
Repeat the loop until you have n odd numbers in the randomArray
For the method measureTime, you can implement the following steps:
Create an empty array called bottomTen with a size of 10
Use a sorting algorithm to sort the numbers array
Copy the first 10 smallest numbers from the sorted array to the bottomTen array
Measure the time it takes to perform the above steps
Perform multiple time measurements with different input sizes to determine the time complexity
Add a block comment at the end of the method stating the appropriate time complexity category based on the measurements
Regarding the Comparator BY_NAME, you can:
Add a nested private class named BY_NAME inside the Friend class to implement the comparator
Add a public static final field called BY_NAME of type Comparator to allow other classes to access the comparator
In the method displayFriends, to print the friends sorted by name, you can:
Add a third section with the header Friends sorted by name:
Use a suitable sorting algorithm like Merge or Quick sort to sort the friends array by name
Print the sorted friends array in the desired format