Question

please illistrate a UML diagram for the following code bellow, it should have 3 rows, 1...

please illistrate a UML diagram for the following code bellow, it should have 3 rows, 1 colum like the one bellow, first box should have the class name, second box is for class attributes, and third box should have the class operations/methods and please put a (+) for public and a (-) for private

example:

class

+-attributes

+-Operations

Also make a JAVADOCs, but not generated by a compiler, to explain what is going on in the code

import java.util.Random;

public class TestClass {
  
public static void main(String[] args) {
  
int bubbleValues[] = new int[20];
int selectionValues[] = new int[20];
int insertionValues[] = new int[20];
int quickValues[] = new int[20];
  
Random input = new Random();
  
for(int i = 0; i < 20; i++){
bubbleValues[i] = input.nextInt(100);
selectionValues[i] = input.nextInt(100);
insertionValues[i] = input.nextInt(100);
quickValues[i] = input.nextInt(100);
}
  
SortingBenchMarks in = new SortingBenchMarks();
  
int bubbleCount = in.bubbleSort(bubbleValues);
int selectionCount = in.selectionSort(selectionValues);
int insertionCount = in.insertionSort(insertionValues);
int quickCount = in.quickSort(quickValues);
  
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( " " +insertionValues[i]);
}
System.out.println();
System.out.println("Elements in the quick array:");
for(int i = 0; i <20; i++){
System.out.print( " " +quickValues[i]);
}
System.out.println();
  
System.out.println("Bubble swaps: " +bubbleCount);
System.out.println("Selection swaps: " +selectionCount);
System.out.println("Insertion swaps: " +insertionCount);
System.out.println("Quick swaps: " +quickCount);
}

}

=============================================================================================

public class SortingBenchMarks {
  
int bubbleCount = 0;
int selectionCount = 0;
int insertionCount = 0;
int quickCount = 0;
  
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(array[index] > array[index + 1]){
temp = array[index];
array[index] = array[index + 1];
array[index + 1] = temp;
  
bubbleCount += 2;
}
}
}
  
return bubbleCount;
}
public int selectionSort(int[] array) {
  
int strtScan;
int indx;
int minIndx;
int miniValue;
  
for(strtScan = 0; strtScan < (array.length-1); strtScan++){
minIndx = strtScan;
miniValue = array[strtScan];
  
for(indx = strtScan + 1; indx < array.length; indx++){
if(array[indx] < miniValue){
miniValue = array[indx];
minIndx = indx;
}
  
}
  
array[minIndx] = array[strtScan];
array[strtScan] = miniValue;
  
selectionCount += 2;
}
return selectionCount;
}
  
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--;
insertionCount++;
}
  
array[scan] = unsortedValue;
insertionCount++;
}
return insertionCount;
}
  
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;
  
quickCount += 2;
}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Random;
public class TestClass {
  
public static void main(String[] args) {
  
int bubbleValues[] = new int[20];
int selectionValues[] = new int[20];
int insertionValues[] = new int[20];
int quickValues[] = new int[20];
  
Random input = new Random(); // creating the object of class Random to create random numbers
/*
       below loop will insert random numbers in the arrays
   */
for(int i = 0; i < 20; i++){
bubbleValues[i] = input.nextInt(100);
selectionValues[i] = input.nextInt(100);
insertionValues[i] = input.nextInt(100);
quickValues[i] = input.nextInt(100);
}
  
   // creating object of SortingBenchMarks class
SortingBenchMarks in = new SortingBenchMarks();
  
     
int bubbleCount = in.bubbleSort(bubbleValues); //this line of code will sort the array and return the number of swaps occured during bubble sort
int selectionCount = in.selectionSort(selectionValues); //this line of code will sort the array and return the number of swaps occured during selection sort
int insertionCount = in.insertionSort(insertionValues);//this line of code will sort the array and return the number of swaps occured during insertion sort
int quickCount = in.quickSort(quickValues);//this line of code will sort the array and return the number of swaps occured during quick sort
  
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( " " +insertionValues[i]);
}
System.out.println();
System.out.println("Elements in the quick array:");
for(int i = 0; i <20; i++){
System.out.print( " " +quickValues[i]);
}
System.out.println();
  
System.out.println("Bubble swaps: " +bubbleCount);
System.out.println("Selection swaps: " +selectionCount);
System.out.println("Insertion swaps: " +insertionCount);
System.out.println("Quick swaps: " +quickCount);
}
}
=============================================================================================


public class SortingBenchMarks {
  
int bubbleCount = 0;
int selectionCount = 0;
int insertionCount = 0;
int quickCount = 0;
/*
   function to sort arry using bubble sort technique
   this function will return the number of swaps that occured while sorting the array using bubble sort
*/
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(array[index] > array[index + 1]){
temp = array[index];
array[index] = array[index + 1];
array[index + 1] = temp;
  
bubbleCount += 2;
}
}
}
  
return bubbleCount;
}
   /*
   function to sort arry using selection sort technique
   this function will return the number of swaps that occured while sorting the array using selection sort
*/

public int selectionSort(int[] array) {
  
int strtScan;
int indx;
int minIndx;
int miniValue;
  
for(strtScan = 0; strtScan < (array.length-1); strtScan++){
minIndx = strtScan;
miniValue = array[strtScan];
  
for(indx = strtScan + 1; indx < array.length; indx++){
if(array[indx] < miniValue){
miniValue = array[indx];
minIndx = indx;
}
  
}
  
array[minIndx] = array[strtScan];
array[strtScan] = miniValue;
  
selectionCount += 2;
}
return selectionCount;
}
  
/*
   function to sort arry using insertion sort technique
   this function will return the number of swaps that occured while sorting the array using insertion sort
*/
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--;
insertionCount++;
}
  
array[scan] = unsortedValue;
insertionCount++;
}
return insertionCount;
}
  
/*
   function to sort arry using Quick sort technique
   this function will return the number of swaps that occured while sorting the array using quick sort
*/
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;
}
  
/*
   function to swap array elements at index a and b
*/
private void swap(int[] array, int a, int b){
int temp;
temp = array[a];
array[a] = array[b];
array[b] = temp;
  
quickCount += 2;
}
}

class diagram

Documenti Microsoft Word Table Tools Home Insert Page Layout ReferencesMailings ReviewViewDeveloper Design Layout Find ▼ e Re

Add a comment
Know the answer?
Add Answer to:
please illistrate a UML diagram for the following code bellow, it should have 3 rows, 1...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In the most basic/easiest JAVA please change the following code into RECURISON make sure the prog...

    In the most basic/easiest JAVA please change the following code into RECURISON make sure the program complies correctly. (It is currently in iterative.) please show comments how they are different after. //public class public class MergeSort { public static void mergeSort(int[] array) { int start; int i; int minScan; int minValue; int counter = 0; /** The outer loop iterates once for each element in the array. The start variable marks the position where the scan should begin. **/ for(start...

  • The following code is a Java code for insertion sort. I would like this code to...

    The following code is a Java code for insertion sort. I would like this code to be modified by not allowing more than 10 numbers of integer elements (if the user enters 11 or a higher number, an error should appear) and also finding the range of the elements after sorting. /* * Java Program to Implement Insertion Sort */ import java.util.Scanner; /* Class InsertionSort */ public class InsertionSortTwo { /* Insertion Sort function */ public static void sort( int...

  • In the code shown above are two parts of two different exercises. HOW WE CAN HAVE...

    In the code shown above are two parts of two different exercises. HOW WE CAN HAVE BOTH OF THEM ON THE SAME CLASS BUT SO WE CAN RECALL them threw different methods. Thank you. 1-First exercise import java.util.Scanner; public class first { public static int average(int[] array){    int total = 0;    for(int x: array)        total += x;    return total / array.length;    } public static double average(double[] array){    double total = 0;    for(double x: array)        total += x;    return total /...

  • the code needs to be modifed. require a output for the code Java Program to Implement...

    the code needs to be modifed. require a output for the code Java Program to Implement Insertion Sort import java.util.Scanner; /Class InsertionSort * public class Insertion Sort { /Insertion Sort function */ public static void sort( int arr) int N- arr.length; int i, j, temp; for (i-1; i< N; i++) j-i temp arrli; while (j> 0 && temp < arrli-1) arrli]-arrli-1]; j-j-1; } arrlj] temp; /Main method * public static void main(String [] args) { Scanner scan new Scanner( System.in...

  • Hello this is my java sorting algorithm program i need all of my errors corrected so...

    Hello this is my java sorting algorithm program i need all of my errors corrected so I can run it. thank you!! import java.util.Scanner;    public class SortingAlogs { public static void main(String[]args){ int array [] = {9,11,15,34,1}; Scanner KB = new Scanner(System.in); int ch; while (true) { System.out.println("1 Bubble sort\n2 Insertion sort\n3 Selection sort\n"); ch = KB.nextInt(); if (ch==1)    bubbleSort(array); if (ch==2)    insertion(array); if (ch==3)    Selection(array); if (ch==4) break;    print(array);    System.out.println(); }    }...

  • The code snippet below is an example of pass by reference. We also provide a sample...

    The code snippet below is an example of pass by reference. We also provide a sample method setZeroAt, which sets 0 at a position i in the array, to illustrate pass by reference. public class Sample { public static void setZeroAt(int [] arr, int i){ arr[i] = 0; } public static void main(String[] args) { Scanner input = new Scanner(System.in); int sample[] = {1, 2, 3}; setZeroAt(sample, 1); //Now sample looks like {1, 0, 3} } } Write a Java...

  • Create a program called GeneralizedBubbleSort that will make use of the Comparable Interface in the same...

    Create a program called GeneralizedBubbleSort that will make use of the Comparable Interface in the same way it is used in the GeneralizedSelectionSort. You should use the attached ComparableDemo to test your program. public class ComparableDemo { public static void main(String[] args) { Double[] d = new Double[10]; for (int i = 0; i < d.length; i++) d[i] = new Double(d.length - i); System.out.println("Before sorting:"); int i; for (i = 0; i < d.length; i++) System.out.print(d[i].doubleValue( ) + ", ");...

  • In JAVA Thank You What is the exact output produced by running the method test? /**...

    In JAVA Thank You What is the exact output produced by running the method test? /** * TestSwap.java * Demonstrates parameter passing involving arrays and integers, * scope of variables, flow of control, and overloaded methods. */ public class TestSwap { public void swap (int x, int y) { int temp; temp = x; x = y; y = temp; System.out.println("Inside swap version 1:"); System.out.println("x = " + x); System.out.println("y = " + y); } public void swap (int[] a,...

  • PLEASE ANSWER #5AND #6, THE ANSWER FOR #3 AND #4 ARE ALREADY PROVIDED!!! 3 .Using Java,...

    PLEASE ANSWER #5AND #6, THE ANSWER FOR #3 AND #4 ARE ALREADY PROVIDED!!! 3 .Using Java, Write a computer program that prompts the user for one number, n for the number of items in the array to sort, and create and sort 1000 arrays of this size timing the run to get an average time to sort an array of this size. Then do the following: Initiate a variable running_time to 0 Create a for loop that iterates 1000 times....

  • On the following code there is an error bc you are not reverting back to the...

    On the following code there is an error bc you are not reverting back to the original order after a sort. For the next sort you are passing the same reference variable to the next method. But that will point to the same (already sorted) array on the memory. Hence after the first sorting method, all three sorting methods are working on the already sorted array. Do the following : Just copy each data set to 4 different arrays -...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT