Question

In: Computer Science

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

3.

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

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

    Question 3(a)

    • /** Returns the number of 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 a parameter and returns an array of length two, where the first element is the maximum value in scores and the second element is the minimum value in scores. Complete the method findMaxAndMin below.

    Question 3(b)

    • /** Returns an array of 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 a parameter and computes and returns the average score. However, if the size of the array scores is 6 or greater, and the maximum value occurs only once in the array, that value is excluded from computing the average. The same is done for the minimum value.

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

    Question 3(c)

    • /** Returns the average 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)

Solutions

Expert Solution

/** Returns the number of 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)

{

    int i, count = 0;

   

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

    {

        // if the current element is the required elements

        if( scores[i] == target )

            count++;

    }

   

    return count;

}

/** Returns an array of 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)

{

    // initialize with the first element

    int max = scores[0];

    int min = scores[0];

   

    int i;

   

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

    {

        // if the current element is smaller than min

        if( scores[i] < min )

            min = scores[i];

       

        // if the current element is larger than min

        if( scores[i] > max )

            max = scores[i];

    }

   

    int[] arr = new int[2];

    arr[0] = min;

    arr[1] = max;

   

    return arr;

}

/** Returns the average 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)

{

    // store the total of all elements in array scores

    double sum = 0;

   

    int i;

   

    // traverse the array

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

        sum += scores[i];

   

    // calculate average

    double average = sum / (double)scores.length;

    return average;


Related Solutions

A person tried by a 3-judge panel is declared guilty if at least 2 judges cast...
A person tried by a 3-judge panel is declared guilty if at least 2 judges cast votes of guilty. Suppose that when the defendant is in fact guilty, each judge will independently vote guilty with probability 0.7, whereas when the defendant is in fact innocent, this probability drops to 0.2. If 70 percent of defendants are guilty, compute the conditional probability that judge number 3 votes guilty given that (a) judges 1 and 2 vote guilty; (b) judges 1 and...
The management potential of future administrators was rated by a panel of three judges. Each judge...
The management potential of future administrators was rated by a panel of three judges. Each judge rated a candidate on a scale of 1 (high performance) to 6 (low performance). However before using these ratings to choose a candidate, the firm wanted to check the reliability of the raters to see if there was a difference between the ratings of the judges. The data are included below. Many times one judge will be stricter on his/her rating of a candidate’s...
Below are two judges’ rankings of bands at a marching band competition. Calculate the Covariance, Coefficient...
Below are two judges’ rankings of bands at a marching band competition. Calculate the Covariance, Coefficient of Correlation, the Least Squares Equation and the Coefficient of Determination. Also, use your equation of calculate Judge 2’s rank of the bands if Judge 1 ranks them a 4. Judge 1 (x) Judge 2 (y) 1 6 3 4 4 5 7 1 5 3 6 2 2 7
Describe the different forms of competition and give specific examples of these competitors with regard to...
Describe the different forms of competition and give specific examples of these competitors with regard to a particular firm. Explain the strategic choices as to how these firms are positioning themselves to handle these competitors.+ 500 word minimum
1. An impartial judge of a local garden competition collects scores from two groups of judges...
1. An impartial judge of a local garden competition collects scores from two groups of judges on what he suspects to be the number one garden. He finds the first group (n = 5) has a mean score of 76. The second group (n = 3) has a mean score of 91. So that he may declare the final score, what is the weighted mean of these two groups? 2. A social scientist measures the number of minutes (per day)...
Who are Open-Panel Model HMO's competitors and how do they compare in market, membership, assets, equality,...
Who are Open-Panel Model HMO's competitors and how do they compare in market, membership, assets, equality, and profit?
Instructions A particular talent competition has five judges, each of whom awards a score between 0...
Instructions A particular talent competition has five judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores, such as 8.3, are allowed. A performer’s final score is determined by dropping the highest and lowest score received, then averaging the three remaining scores. Write a program in Python that uses this method to calculate a contestant’s score. It should include the following functions: getJudgeData( ) should ask the user for a judge’s score, and validate...
1. Provide a description of competition. 2.What is the value of positioning in relationship to competitors?
1. Provide a description of competition. 2.What is the value of positioning in relationship to competitors?
Walmart 's competitors at regional level as well as global level . what challenges of competition...
Walmart 's competitors at regional level as well as global level . what challenges of competition Walmart is facing globally ? how Walmart overcome its competitors. explain in 800 words minimum.
To protect a domestic industry from foreign competition by raising the price of foreign competitors’ products,...
To protect a domestic industry from foreign competition by raising the price of foreign competitors’ products, Brazil could impose foreign-exchange controls. establish an embargo. impose a nontariff barrier. levy an import tariff. set an import quota. Which of the following includes Brazil as a member? The Common Market, also called the European Union The Common Market of the Southern Cone North American Free Trade Agreement The Commonwealth of Independent States Central American Free Trade Agreement
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT