3. In an international ballroom dancing competition, competitors are scored by a panel of judges on a...

60.1K

Verified Solution

Question

Programming

3.

In an international ballroom dancing competition, competitorsare scored by a panel of judges on a scale from 0 to 100. The finalscore for each couple is computed as the average of the scores fromall the judges. However, if the number of judges is equal to orgreater than 6, and the highest score is given by only one judge,that score is excluded from computing the average. The same appliesto the lowest score.

  1. Write a method countOccurrences that returns the number ofoccurrences of a given target value in a given array. Complete themethod countOccurrences below.

    Question 3(a)

    • /** Returns the numberof times target occurs among the values
      * in the given array
      * @param scores an array of values
      * @param target the target value
      * @return the number of times target appears among the
      * values in scores
      */
      public static int countOccurrences(int[] scores, int target)

  2. Write a method findMaxAndMin that takes an array scores as aparameter and returns an array of length two, where the firstelement is the maximum value in scores and the second element isthe minimum value in scores. Complete the method findMaxAndMinbelow.

    Question 3(b)

    • /** Returns an arrayof two elements in which
      * the first element is the maximum value in scores and
      * the second element is the minimum value in scores
      * Precondition: scores.length > 0; 0 <=scores[k] <= 100
      */
      public static int[] findMaxAndMin(int[] scores)

  3. Write a method averageScore that takes an array scores as aparameter and computes and returns the average score. However, ifthe size of the array scores is 6 or greater, and the maximum valueoccurs only once in the array, that value is excluded fromcomputing the average. The same is done for the minimum value.

    In writing this method, assume that the methods countOccurrencesfrom Part (a) and findMaxAndMin from Part (b) work as specified,regardless of what you wrote there. You may not receive full creditif instead of calling these methods you write equivalent code here.Complete the method averageScore below.

    Question 3(c)

    • /** Returns theaverage of the values in scores. However,
      * if the size of the array scores is not less than 6 and
      * the largest value occurs only once in scores, that value
      * is excluded from computing the average; the same for
      * the smallest value.
      * Precondition: scores.length >= 3; 0 <=scores[k] <= 100
      */
      public static double averageScore(int[] scores)

Answer & Explanation Solved by verified expert
4.3 Ratings (825 Votes)
Returns the number of times target occurs among the values    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students