[Solved]Lab 13 Instructions Sorting Array Double Values Background Understand Java Jvm Us Sort Col Q37156901



Lab 13 Instructions Sorting an Array of Double Values Background To understand what Java and the JVM are doing for us when we sort a Collection, it is useful to have some experience coding a sort algorithm. In this lab, you will sort an array of double values into ascending order. The array will contain randomly generated values (that code is provided to you). You may use any sort algorithm you choose, so long as the sort produces correct results. Provided to You The following are provided to you: * These instructions Code to declare and instantiate an array of (pseudo)random double values. The method provided (generateData) returns a reference to the completed array Sample Output (below) * Requirements Choose a sort algorithm to code. Any algorithm will work for the sort. * Suggestion: The examples in Chapter 19 can be very useful. Recommendation: Write the sort code in its own method(s) and pass the array reference returned by the provided code to your sort method Further Recommendation: Modularize your code as much as possible. It can make it easier to pinpoint logic issues that way. o o o Import the Random class from the util package Use the provided method (generateData) to generate values and load an array. The provided code will return the completed array by reference Sort the (pseudo)randomly generated array into ascending order (smallest to largest) and output the sorted data * . Name your code Lab13.java * Submit your completed code as an attachment to the lab assignment NOTES: Keep in mind that the values are type double; the subscripts into the array are type int. As a reminder, any submission that does not compile cleanly or execute without any unexpected issues will earn a grade of zero. Sample Output The values displayed will vary with every execution, as they are (pseudo)randomly generated. However, in all cases, the second set of output must be in sorted, ascending order. Original Sequence of Doubles in Array 0.104731 0.170890 0.136273 0.430977 0.981152 0.244061 0.832665 0.081479 0.681254 0.724836 Double Values as Sorted 0.081479 0.104731 0.136273 0.170890 0.244061 0.430977 0.681254 0.724836 0.832665 0.981152 Method generateData * Method generates double values and uses them to load an array. This code is provided to students. * The method will return a reference to the completed/loaded array. The sort process *will then be executed on that array reference private static double[ ] generateData) int double arraySize – 10; numbersnew double arraysize ];/1 declare & instantiate EMPTY array // size of array random new Random(); // declare & instantiate a randomizer * The following loop wil1 (pseudo)randomly generate double values to load the array *It uses the arraySize variable as the limiter for the loop. Thus, changing BOTH the size *of the array and the number of loop iterations requires changing only one variable for( int subscript 0; subscript < arraySize; subscript++) // Random generation range is from e (inclusive) to 1 (exclusive) numbers[ subscript ]-random.nextDouble( ); // end for loop // Show the original item sequence in array; for comparison to sorted sequence System.out . printf( “Original sequence of Doubles in Array%n” ); for( double nbr: numbers) System . out . printf( // end for loop “%f%n”, ); nbr ) return numbers; // end generateData Show transcribed image text Lab 13 Instructions Sorting an Array of Double Values Background To understand what Java and the JVM are doing for us when we sort a Collection, it is useful to have some experience coding a sort algorithm. In this lab, you will sort an array of double values into ascending order. The array will contain randomly generated values (that code is provided to you). You may use any sort algorithm you choose, so long as the sort produces correct results. Provided to You The following are provided to you: * These instructions Code to declare and instantiate an array of (pseudo)random double values. The method provided (generateData) returns a reference to the completed array Sample Output (below) * Requirements Choose a sort algorithm to code. Any algorithm will work for the sort. * Suggestion: The examples in Chapter 19 can be very useful. Recommendation: Write the sort code in its own method(s) and pass the array reference returned by the provided code to your sort method Further Recommendation: Modularize your code as much as possible. It can make it easier to pinpoint logic issues that way. o o o Import the Random class from the util package Use the provided method (generateData) to generate values and load an array. The provided code will return the completed array by reference Sort the (pseudo)randomly generated array into ascending order (smallest to largest) and output the sorted data * . Name your code Lab13.java * Submit your completed code as an attachment to the lab assignment NOTES: Keep in mind that the values are type double; the subscripts into the array are type int. As a reminder, any submission that does not compile cleanly or execute without any unexpected issues will earn a grade of zero.
Sample Output The values displayed will vary with every execution, as they are (pseudo)randomly generated. However, in all cases, the second set of output must be in sorted, ascending order. Original Sequence of Doubles in Array 0.104731 0.170890 0.136273 0.430977 0.981152 0.244061 0.832665 0.081479 0.681254 0.724836 Double Values as Sorted 0.081479 0.104731 0.136273 0.170890 0.244061 0.430977 0.681254 0.724836 0.832665 0.981152
Method generateData * Method generates double values and uses them to load an array. This code is provided to students. * The method will return a reference to the completed/loaded array. The sort process *will then be executed on that array reference private static double[ ] generateData) int double arraySize – 10; numbersnew double arraysize ];/1 declare & instantiate EMPTY array // size of array random new Random(); // declare & instantiate a randomizer * The following loop wil1 (pseudo)randomly generate double values to load the array *It uses the arraySize variable as the limiter for the loop. Thus, changing BOTH the size *of the array and the number of loop iterations requires changing only one variable for( int subscript 0; subscript
Expert Answer
Answer to Lab 13 Instructions Sorting an Array of Double Values Background To understand what Java and the JVM are doing for us wh… . . .
OR

