How do I call the method generate_data using the user input for the length of the array?

Write a program that will sort a list of arbitrarily generated integers in descending order.

Let the user determine how many arbitrary and unique numbers to sort from 1 to 10000. Use the random method from the Math class to generate random integer numbers from one to 10000. Remove all duplicate numbers. Also, keep a count of the duplicate numbers generated. Make sure that the requested number of unique but arbitrary values are generated. This means that an additional number must be generated for each duplicate. (For example, suppose the user requested 1000 numbers to be sorted. Generating the 1000 numbers could result in perhaps 20 duplicated numbers. These duplicated numbers must be removed and another 20 new random numbers must be generated. Some of these 20 new random numbers could be duplicates of the other 980 numbers. If so, they must be removed and new random numbers must be generated to replace them. This process continues until the total number of unique numbers is what the user requested (i.e., 1000 for this example).

After the sorted list has been generated with no duplicates, output the size of the list and the count of the number of duplicates generated. Next, list with the sorted values ten per line in descending order. Pause after printing 10 lines to allow the user to see 100 values at one time.

Let the user check to see if a certain value is in the list. Implement a modified linear search and a modified binary search to count the number of comparisons and to take into account that the array is in descending order. A comparison occurs whenever an element of an array is compared to a value. Assigning a value to an array element is not considered a comparison.

Both methods should output the number of comparisons. Output the location of the value if found; otherwise, output an appropriate message. Regardless of whether the value exists or not in the list, output the number of comparisons performed!

This is what I have so far...I don't know where to do from here... :/

Thank you!

import java.util.Scanner;

public class Project4 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("How many arbitrary numbers to sort from 1 to 10000? ");

int i = input.nextInt();

}

public static void sort_data(int[] list) {

for (int i = 0; i<list.length-1; i++) {

int currentMax = list[i];

int currentMaxIndex = i;

for (int j = i + 1; j < list.length; j++) {

if (currentMax < list[j]) {

currentMax = list[j];

currentMaxIndex = j;

}

}

if (currentMaxIndex !=i) {

list[currentMaxIndex] = list[i];

list[i] = currentMax;

}

}

}

public static int generate_data (int[] list) {

for (int i = 0; i < list.length; i++) {

int index = (int)(Math.random() * list.length);

int temp = list[i];

list[i] = list[index];

list[index] = temp;

}

return 555;

}

public static int linear_search (int[] list, int target) {

System.out.print("What number to search for?");

for (int i = 0; i < list.length; i++) {

if (target == list[i])

return i;

}

return -1;

}

public static int binary_search(int[] list, int target) {

int high = 0;

int low = list.length - 1;

while (low >= high) {

int mid = (low + high) / 2;

if (target > list[mid])

low = mid-1;

else if (target == list[mid])

return mid;

else

high = mid + 1;

}

return -high - 1;

}

public static void printArray (int[] list, int duplicates) {

int count = 1;

for (int i = 2; ; i++) {

System.out.print(i + " ");

if (count % 10 == 0) {

System.out.println();

}

if (count == 100) {

break;

}

count++;

}

}

}

Tweet This+ 1 thisPost To Linkedin