Question: Needs to be done in JAVA. If there is something that you need please let me know from my understanding all the code is here

Needs to be done in JAVA. If there is something that you need please let me know from my understanding all the code is here for sorting and making a file is here. I just want a good example of how to change values in a code as described here: Please add code that a user enters pick the number of random objects that are sorted and the number of times the sorting will run through right now it is at 10,000 random objects and repeats 5 times. It needs to request both object number and number of times it repeats then runs.

import java.io.*; public class BubbleSort { static File diskFile; static PrintWriter pw; //method that will sort the array public static void bubbleSort(int[] arr) { // sort the array using bubble sort int n = arr.length; // length of array in n variable for (int i = 0; i < n - 1; i++) // loop variable array -1 size for (int j = 0; j < n - i - 1; j++) // loop array variable -i-1 if (arr[j] > arr[j + 1]) // check if array of j index value is greater than array of j+1 { // swap temp and arr[i] int temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } public static void main(String[] args) { System.out.println("Start bubble sort "); startBubbleSort(); System.out.println("End Bubble sort "); } public static void startBubbleSort() { int number_of_tests; number_of_tests = 5; int size = 10000; int[] array = new int[size]; long startTime = 0; long endTime = 0; long duration = 0; try { diskFile = new File("bubble data"); try { pw = new PrintWriter(diskFile); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } pw.println("Test Number\tSmaple Size\tTime"); for (int currentTest = 1; currentTest <= number_of_tests; currentTest = currentTest + 1) { System.out.println("Starting Time: " + currentTest); for (int i = 0; i < array.length; i++) { array[i] = (int) (Math.random() * size + 1); } startTime = System.nanoTime(); System.out.println("Sorting Array for Test : " + currentTest + " "); bubbleSort(array); endTime = System.nanoTime(); duration = endTime - startTime; System.out.println("Current Test: " + currentTest + ","); System.out.print("Sample Size:" + size + ","); System.out.print("Time to complete Bubble Sort: "); System.out.printf("%12.5f %n", (double) duration / 1000000000); printReportItem(duration, size, currentTest, pw); } } finally { pw.close(); } } public static void printReportItem(long duration, int size, int testNumber, PrintWriter pw) { double time = duration / 1000000000.00; pw.print(testNumber + "\t\t\t"); pw.print(size + "\t\t"); pw.println(time); // System.out.println("Current Test: " + currentTest + ","); System.out.print("Sample Size:" + size + ","); System.out.print("Time to complete Bubble Sort: "); System.out.printf("%12.5f %n", (double) duration / 1000000000); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!