Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA Assignment Your assignment is to write a program that creates a single dime

ID: 3768507 • Letter: J

Question

JAVA Assignment

Your assignment is to write a program that creates a single dimensioned array of integers fills it with random numbers, then sorts the array, and does searches in the array.

Your program must first request the user to input an array size. This size may be any integer from 1 to 20,000 (make certain to verify that the number is within this range and if not, ask for a number again and again until you get a number if the correct range). Next you program will create an array of this size and fill the array with random numbers from 1 and the array size. Next it will copy this array into another array that your program crates that is the same size. The program then invokes a method that you will create that sorts the input array (but not the copied one). This method is to have a single input, the array. Next if the size of the array is 16 or less, the program will display the contents of both the sorted and unsorted arrays so that the sort routine can be verified.

Next the program will solicit a search number between 1 and array size from the user (make certain to verify that the number is within this range and if not, ask for a number again and again until you get a number if the correct range).

Next your program will invoke a method you will write that uses a linear search to find the input search number in the sorted array. The method will return the position within the array (0 to array size less 1) if it finds the number. Otherwise it will return a minus one. The program will then display a message giving the location of the find or state that the number was not in the array. Immediately before and after the invoke of the search, your program is to invoke System.nanoTime() (use the Internet to find out how to use this) and save these values in variables of type long. It then subtracts the before time from the after time and displays the difference with a message stating how long the linear search took in milliseconds.

Next your program will invoke a method you will write that uses a binary search to find the search number in the sorted array. The method will return the position within the array (0 to array size less 1) if it finds the number, otherwise it will return a minus one. Immediately before and after the invoke of the search, your program is to invoke System.nanoTime() and save these values. It then subtracts the before time from the after time and displays the difference with a message stating how long the binary search took in milliseconds.

Also make a flow chart of your program and hand it in. Make certain to show all loops, ifs, and processing symbols.

Thank you.

Explanation / Answer

program :