View the step-by-step solution to:

Question


Requesting help to solve this. I'm behind in class. 

  1. Declare an array of double type, of

size 10.

  • 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 Math.random().
  • Invoke a method named printArray in the same class, to print all elements of this array in one line, with a space separating adjacent array elements, and then 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 printArray takes only one parameter, which is a double type one-dimensional array, and the method return type is void. Use a for-each loop in this method to navigate through the array. Refer to "LinearSearch.java", line 45~47 on how to implement a for-each loop.
  • Invoke sort in the same class, to sort this array in descending order. This method takes only one parameter, which is a double type array, and its return type is void. You must choose one of these three algorithms: selection, insertion, or bubble sort. The source code of these three algorithms is in the zip file "search-and-sorting.zip". You need to modify the source code of the sorting algorithm you choose, and make it usable in this homework.
  • Note: You cannot invoke any existing sorting method from any Java library class, such as the sort method in java class Arrays. The purpose of this homework is to have you modify the sorting algorithm source code to get a better understanding of how a sorting algorithm works.

    1. Invoke printArray 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.
    • Inside the main method, invoke printArray and sort.
    • The signatures of printArray and sort have already been defined in step 3 and 4 above, and you cannot change the signatures nor the return types
    • Because the required sort order in this homework is decreasing order, you need to make a modification on the sorting algorithm provided in the file "search-and-sorting.zip" (they are all increasing sort). As stated in Step 4 above, you can choose which sorting algorithm to use.
    • Add suitable comments in the source code.

    public class NameHw6 {

       public static void main(String[] args) 

       {

          final int SIZE = 10;

          

          double [] scores = new double [SIZE];

          for(int i = 0; i < scores.length; i++)

          {

             scores[i] = (double) (Math.random() * 100);

          }

          

          for (double eachElement: scores)

          {

             System.out.printf("%4.Of ", eachElement);

          }

       }

    }


    Code above is what I have so far. Thanks

    Recently Asked Questions

    Why Join Course Hero?

    Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

    • -

      Study Documents

      Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

      Browse Documents
    • -

      Question & Answers

      Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

      Ask a Question
    Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
    Answers in as fast as 15 minutes