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

SortingBenchmarks.java: class, interface, or enum expected import java.util.Rand

ID: 3530796 • Letter: S

Question

SortingBenchmarks.java: class, interface, or enum expected import java.util.Random; ^ 1 error /* Project2SortingBenchmarks class demonstrates the bubbleSort, selectionSort, insertionSort and quickSort methods. */ public class Project2SortingBenchmarks { int bubbleCount = 0; int selectionCount = 0; int insertionCount = 0; int quickCount = 0; /* bubbleSort method returns the number of swaps occured */ public int bubbleSort(int[] array) { int maxElement; int index; int temp; for (maxElement = array.length - 1; maxElement >= 0; maxElement--) { for (index = 0; index <= maxElement - 1; index++) { if (aaray[index] > array[index + 1]) { temp = array[index]; array[index] = array[index + 1]; array[index + 1] = temp; // count the swaps bubbleCount += 2; } } } return bubbleCount; } // end of bubbleSort method /* selectionSort method returns the number of swaps occurred */ public int selectionSort(int[] array) { int startScan; int index; int minIndex; int minValue; for (startScan = 0; startScan < (array.length-1); startScan++) { minIndex = startScan; minValue = array[startScan]; for(index = startScan + 1; index < array.length; index++) { if (array[index] < minValue) { minValue = array[index]; minIndex = index; } } array[minIndex] = array[startScan]; array[startScan] = minValue; // count the swaps selectionCount += 2; } return selectionCount; }// end of selectionSort method /* insertionSort method returns the number of swaps occurred */ public int insertionSort(int[] array) { int unsortedValue; int scan; for (int index = 1; index < array.length; index++) { unsortedValue = array[index]; scan = index; while (scan > 0 && array[scan-1] > unsortedValue) { array[scan] = array[scan - 1]; scan--; // count the swaps insertionCount++; } array[scan] = unsortedValue; // count the swaps insertionCount++; } return insertionCount; }// end of insertionSort method /* quickSort method returns the number of swaps occurred */ public int quickSort(int array[]) { doQuickSort(array, 0, array.length - 1); return quickCount; } private void doQuickSort(int array[], int start, int end) { int pivotPoint; if (start < end) { pivotPoint =partition(array, start, end); doQuickSort(array, start, pivotPoint - 1); doQuickSort(array, pivotPoint + 1, end); } } private int partition(int array[], int start, int end) { int pivotValue; int endOfLeftList; int mid; mid = (start + end) / 2; swap(array, start, mid); pivotValue = array[start]; endOfLeftList = start; for (int scan = start + 1; scan <= end; scan++) { if (array[scan] < pivotValue) { endOfLeftList++; swap(array, endOfLeftList, scan); } } swap(array, start, endOfLeftList); return endOfLeftList; } private void swap(int[] array, int a, int b) { int temp; temp = array[a]; array[a] = array[b]; array[b] = temp; // count the swaps quickCount += 2; } }// end of Project2SortingBenchmarks class /* Class SortingBenchMarks demonstrates the Project2SortingBenchmarks class. */ import java.util.Random; public class SortingBenchMarks { public static void main(String[] args) { // initialize the four identical arrays int bubbleValues[] = new int[20]; int selectionValues[] = new int[20]; int insertionValues[] = new int[20]; int quickValues[] = new int[20]; // create an object for Random class // insert the random values into four arrays for(int i = 0; i < 20; i++) { bubbleValues[i] = random.nextInt(100); selectionValues[i] = random.nextInt(100); insertionValues[i] = random.nextInt(100); quickValues[i] = random.nextInt(100); } // create an object for Project2SortingBenchmarks class Project2SortingBenchmarks sb = new Project2SortingBenchmarks(); // call to the functions int bubbleCount = sb.bubbleSort(bubbleValues); int selectionCount = sb.selectionSort(selectionValues); int insertionCount = sb.insertionSort(insertionValues); int quickCount = sb.quickSort(quickValues); // display the elements in the arrays System.out.println("Elements in the bubble array:"); for(int i = 0; i < 20; i++) { System.out.print(" " + bubbleValues[i]); } System.out.println(); System.out.println("Elements in the selection array: "); for(int i = 0; i < 20; i++) { System.out.print(" " + selectionValues[i]); } System.out.println(); System.out.println("Elements in the insertion array: "); for(int i = 0; i < 20; i++) { System.out.print(" " + inserttionValues[i]); } System.out.println(); System.out.println("Elements in the quick array: "); for(int i = 0; i < 20; i++) { System.out.print(" " + quickValues[i]); } /* display the number of swaps in each sorting algorithm */ System.out.println("Bubble swaps: " + bubbleCount); System.out.println("Selection swaps: " + SelectionCount); System.out.println("Insertion swaps: " + insertionCount); System.out.println("Quick swaps: " + quickCount); }// end of main method }// end of SortingBenchMarks class

Explanation / Answer

your code is all mixed, please repost so I can help

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote