Create a UML class diagram of the application illustrating class hierarchy, collaboration, and the content of each class. There is only one class.  There is a main method that calls four methods.  I am not sure if I made the UML Class diagram correct.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Create a UML class diagram of the application illustrating class hierarchy, collaboration, and the content of each class.

There is only one class.  There is a main method that calls four methods.  I am not sure if I made the UML Class diagram correct.


import java.util.Random; // import Random package
import java.util.Scanner; // import Scanner Package

public class SortArray{ // class name

public static void main(String[] args) { //main method

Scanner scanner = new Scanner(System.in); // creates object of the Scanner class
int[] array = initializeArray(scanner);

System.out.print("Array of randomly generated values: ");
displayArray(array); // Prints unsorted array

sortDescending(array); // sort the array in descending order
System.out.print("Values in desending order: ");
displayArray(array); // prints the sorted array, should be in descending order

sortAscending(array); // sort the array in ascending order
System.out.print("Values in asending order: ");
displayArray(array); // prints the sorted array, should be in ascending order

} // end main()

public static int[] initializeArray(Scanner scan) { //initializeArray method

System.out.print("Enter an array length: "); // ask user to enter a number
int n = scan.nextInt(); // parse user input

// The while loop below validates user input.
// It runs repeatedly until user enters a numbet greater than zero.
while (n <= 0) {
System.out.println("Length of array must be greater than 0.");
System.out.print("Enter an array length: " ); // ask user to enter a number
n = scan.nextInt(); // parse user input
}

int[] myArray = new int[n]; // instantiate array with specified length
Random ranValue = new Random(); // creates random object
int maxValue = 1000; // valid ints: 0-999, 1000 is the upperbound.

for (int i = 0; i < myArray.length; i++) { // loop to access all elements in array
myArray[i] =ranValue.nextInt(maxValue); // storing random integers, from 0-999, in the
// array from index 0
}

return myArray; // return the array of random integers
}

public static void sortDescending(int[] array) { //sortDescending method using bubblesort algorithm
int n = array.length;
for (int i = 0; i < n; i++) {
for (int j = 1; j < (n - i); j++) {
if (array[j - 1] < array[j]) {
//swap the elements
int temp = array[j - 1];
array[j - 1] = array[j];
array[j] = temp;
}
}
}
}

public static void sortAscending(int[] array) { //sortAscending method using bubblesort algorithm
int n = array.length;
for (int i = 0; i < n; i++) {
for (int j = 1; j < (n - i); j++) {
if (array[j - 1] > array[j]) {
//swap elements
int temp = array[j - 1];
array[j - 1] = array[j];
array[j] = temp;
}
}
}
}

public static void displayArray(int[] array) { //displayArray method
for (Integer number : array) {
System.out.print(number + " ");
}
System.out.println();
}

}

SortArray
+initializeArray(myArray int[]), maxValue:int
+sortDesending(array:int[]) , n:int, temp:int
+sortAsecending(array:int[], n:int, temp:int
+displayArray(array[: int])
Transcribed Image Text:SortArray +initializeArray(myArray int[]), maxValue:int +sortDesending(array:int[]) , n:int, temp:int +sortAsecending(array:int[], n:int, temp:int +displayArray(array[: int])
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education