Question: Write a Java program SortArray which defines and use unconstrained array of the integer numbers. The length n of the array should be defined by
Write a Java program SortArray which defines and use unconstrained array of the integer numbers. The length n of the array should be defined by a users input (use Scanner or JOptionPane as an input tool).
When the array length is defined, you will declare the array n elements.
Create and call the initializeArray method, which initializes the array with random numbers generated by Java Random class. See Appendix D in the textbook on how to use Java random numbers generator. Keep random numbers in checkany number cannot contain more than three digits.
Create and use the custom method sortDescending to sort the array values in a descending order. Then create and use the custom method sortAscending() to sort the array in an ascending order. Do not use any of the prebuilt sorting methods of the array classsort methods must be implemented by you from scratch using the Bubble Sort algorithm (see the Bubble Sort video in the course resources, in Chapter 9 of the textbook, and the tutorial at https://www.javatpoint.com/bubble-sort-in-java).
Write a separate displayArray() method that takes the array as an argument and displays the array element values. The first time you will call the array as generated with random numbers. The second time, you will use this method to display descending order array values, and the third time, you will use this method to display ascending order array values.
Make your application user friendly and explain to potential users what they see (i.e., an array of randomly generated values, sorted array values in descending order, sorted array values in ascending order). Format the output in the orderly fashion: initialized array first in a separate line, the descending order array in the next line, then the array in ascending order in the next line.
Add the proper Header to the SortArray.java file. Do not forget to include the proper comments for the code statements in all .java files to explain what those statements do.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
