Limited access

Upgrade to access all content for this subject

The following method should return the average score for a single game bowled across all bowlers on your team who actually bowled that game.

The 2-dimensional array named teamScores is organized as follows: 1) each row is a single bowler on your team, 2) each column is a single game bowled (game 1 is column 0, game 2 is column 1, etc.), and 3) an element of 0 means the bowler did not bowl that game.

    // Precondition: gameNum is the game to find the average score for
   //                                1 <= gameNum <= number of columns in teamScores
  //                                 (i.e. gameNum=1 is the first game, column 0)
  public static double findAvgGameScore (int[][] teamScores, int gameNum)
  {
                  double sum =0, count=0;

                  //insert your code

                  if (count>0)  
                                return sum/count;
                  return 0;
     }

What code should be inserted at //insert your code so that this method returns the average score for a specific game?

A
for (int i=0; i<teamScores.length; i++)
{
    if (teamScores[i][gameNum]>0)
    {
        sum += teamScores[i][gameNum];
        count++;                        
    }
}
B
for (int b=0; b<teamScores.length; b++)
{
    sum += teamScores[b][gameNum-1];
    count++;                        
}
C
for (int b=0; b<teamScores.length; b++)
{
    if (teamScores[b][gameNum-1]>0)
    {
        sum += teamScores[b][gameNum-1];
        count++;                        
    }
}
D
for (int r=0; r<teamScores.length; r++)
{
    for (int c=0; c<teamScores[r].length; c++)
    {
        if (teamScores[r][c]>0)
        {
            sum += teamScores[r][c];
            count++;
        }                        
    }
}
E
for (int r=0; r<teamScores.length; r++)
{
    for (int c=0; c<teamScores[r].length; c++)
    {
        if (teamScores[r][gameNum-1]>0)
        {
            sum += teamScores[r][ gameNum-1];
            count++;
        }                        
    }
}
Select an assignment template