Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

array

bigman2009
bigman2009 


General description for homework 6: In this homework, your program will create an array and then fill it with random values, and then print it out. Then the program will invoke a sort algorithm to sort the array, and then print it to verify that it has been sorted. Here are the detail descriptions for homework 6: First create a Java project in Eclipse, and then create a new class named JohnDoeHw6.java. Replace JohnDoe with your first and last name. At the beginning of JohnDoeHw6.java, add an appropriate program header as what you did in homework 1 part B. In its main method, insert an output statement as the first statement, which outputs your name, course section and semester info. Refer to homework 1 requirement part B, step 3 and 4 for the same requirements on program header and the first line in main method. Use console output method with format: System.out.printf() . No GUI is needed in this homework. No console input is needed, thus no need to import Scanner class. In the main method, then follow the STEPS below: 1. Declare an array of double type, with size 10. 2. Use a regular for loop to generate 10 random double type variables and fill them into the array. The range of the random variables is between 0 and 100, including 0 and excluding 100. Use method Math.random(). 3. Invoke a method named printArray in the same class, to print this array in one line, with a space separating adjacent array elements, and output an end-of-line symbol at the end. You should use printf method to specify the output to have only 2 digits after the decimal point for each double type variable. This method takes only one parameter, which is a double type array, and its return type should be void. Use a for-each loop in this method to navigate through the array. 4. Invoke a method name sort in the same class, to sort this array in decreasing order. This method takes only one parameter, which is a double type array, and its return type should be void. You can choose one algorithm from selection, insertion, or bubble sort, and it is up to you which one to use. 5. Invoke method printArray again to print the array to the screen, to verify that it has been sorted. Implementation requirements: • In class JohnDoeHw6.java, you should have three methods. One is the main method, the second method is printArray. , and the third is sort. Do not put more classes or more methods in the homework, o/w, you are in the wrong track. • Inside the main method, you invoke method printArray and sort. • The signatures of method printArray and sort have already been defined in step 3 and 4 above, and you cannot change the signature nor the return type of this method Attachments Tags Clarifications

Answers

array

sudheer488
sudheer488 



Please find the program along with output in the attachment.
Attachments
Arrays.rar (2 K) Download




Preview
are shown below :"); for(double d:arr1) { System.out.printf(" %.2f ", d) ; } System.out.println(""); } //This method sorts the input array in desecnding order public void bubbleSortInDescendingOrder(double arr3[]) { double temp; System.out.println("The Numbers sorted in Descending order as below:"); for(int i = 0; i < arr3.length;

Output.PNG (88 K) Download Preview

Screenshots
Screenshot
Purchase Answer