Question: Problem Description Design and implement an application that fills an array with random numbers, then uses the Bubble Sort algorithm described below to sort the

Problem Description
Design and implement an application that fills an array with random numbers, then uses the Bubble Sort algorithm described below to sort the contents of the array in ascending order. As sorting algorithms go, Bubble sort is one of the worst in terms of performance, but it does have the benefit of being one of the easiest to conceptualize and implement. :) Wikipedia provides an excellent discussion of the Bubble Sort algorithm as well as visualizations of the sorting process that may be helpful.
Pseudocode is a way of demonstrating how code should be written without getting bogged down in the details of a particular language. The indentations represent code blocks which in Java we represent using curly braces {...}. When I am sketching out a program on a whiteboard, I often use pseudocode to represent the structure of my program because my whiteboard doesn't care about datatypes or semicolons. :)
Pseudocode implementation of the Bubble Sort algorithm
function sort(dataArray):
done = False
while !done
done = True
for( i =1; i < dataArray.length; i++)
if (dataArray[i-1]> dataArray[i])
swap(i-1,i,dataArray)
done = False
Program Design
Begin by copying ArrayUtilities.java from the NumberStats folder into the BubbleSorter folder. This will allow us to reuse both the generateRandomData() and displayArray() static methods. The first method we will implement is a private static method called swap(). It takes two indexes (positions) as well as an array reference as parameters and it will swap the values at the respective positions within the array. This method is made private as we only want it to be accessible from methods inside the ArrayUtilities class. The second method is a public static method called sort(). It takes an array as a parameter and uses the Bubble sort algorithm shown above to sort the values.
Static Methods
Use the following javadoc comments to implement the required functionality in the ArrayUtilities class.
/**
* Swap the values at the positions indicated by index1 and index2
* within the data array. This method modifies the array referenced
* by the variable data. Nothing is returned by the method.
*
* @param index1 Position of value within data array to swap
* @param index2 Position of value within data array to swap
* @param data Reference to an array of integers containing values to be swapped
*/
private static void swap(int index1, int index2, int[] data){...}
/**
* Sort the integer values in the array refeferenced by data in ascending order
* using the Bubble Sort algorithm. This method modifies the array referenced
* by the variable data. Nothing is returned by the method.
*
* @param data Reference to an array of integers to be sorted
*/
public static void sort(int[] data){...}
Driver class
Add code to the main() method in BubbleSorter.java that uses a Scanner to prompt the user for the desired number of elements to generate and a seed value. Pass these values as arguments to ArrayUtilities.generateRandomData() and store the returned array to a local reference variable of the appropriate type. Use ArrayUtilities.displayArray() to display the unsorted values and include a header stating that this is the generated values.
Once it has been confirmed that the array of random ints is being generated properly, pass the array as an argument to ArrayUtilities.sort(), then call ArrayUtilities.displayArray() again, this time with a message stating that this is the sorted values.
Expected Program Output (with sample user input)
-----------------------------
| Simulation Parameters |
-----------------------------
Please enter the desired number of random values: 25
Please enter the seed value: 123
-----------------------------
| Generated Values |
-----------------------------
83,51,77,90,96,58,35,38,86,54,40,27,73,66,38,50,21,86,55,17,23,38,37,51,79
---------

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 Programming Questions!