Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 ad 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 repeats then run the code.

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions

Question

Explain the nature of human resource management.

Answered: 1 week ago

Question

Write a note on Quality circles.

Answered: 1 week ago

Question

Describe how to measure the quality of work life.

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago