Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

I need to have bubble sort added to this code and have it run properly. It is suppose to time the amount of time it

I need to have bubble sort added to this code and have it run properly. It is suppose to time the amount of time it takes to sort an array of 10,000 random objects to sort. Then repeat if for a total of 5 run times. Please put the correct code back in working in Java thank you.

import java.io.*; import java.util.Scanner; public class BubbleSort { static File diskFile; static PrintWriter pw; public static void bubbleSort() { } 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"); pw = new PrintWriter(diskFile); pw.println("Test Number"+","+ "Smaple Size" + ","+ "Time"); 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() * 10000 + 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 +","); pw.print(size +","); 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_2

Step: 3

blur-text-image_3

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

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students explore these related Databases questions

Question

=+j Describe how EU directives impact IHRM.

Answered: 3 weeks ago