Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

this information can be stored in 2d array where each row of the array represent

ID: 3683387 • Letter: T

Question

this information can be stored in 2d array where each row of the array represents a player and each column represents a game. index [i][j] of this array is the number of points scored by player i in the game j (where both i and j start counting from 0) for example index [0][5] would be the number of points scored by tim in game 5.

public static double averagePPG(int[][]scores,int p)

this should return the average points per game of player p, based on the data in the array scores

public static int singleGameScore(int[][]scores, int g)

this should return the total points scored (by entire team) in game g.

public static double averageGameScore(int[][]scores)

this should return the average total points scored (by entitr team) per game

public static int singleGameTopScoringplayer(int[][] scores, int g)

this should return the index of highest scoring player in game g based on data

public static void main(String[]args)

the main method should declare and instantiate a 2d array containing the above data then call your methods on it to verify theyre working properly.

player game 0 game 1 game 2 game 3 game 4 game 5 game 6 tim 20 27 16 23 20 27 18 dora 8 18 14 17 9 12 0 cat 38 19 25 22 19 25 31 sul 17 8 11 21 15 0 9 top 2 1 3 0 10 2 4

Explanation / Answer

/**
* @author Srinivas Palli
*
*/
public class PlayerStatastics {

   /**
   * @param args
   */
   public static void main(String[] args) {

       int[][] scores = { { 20, 27, 16, 23, 20, 27, 18 },
               { 8, 18, 14, 17, 9, 12, 0 }, { 38, 19, 25, 22, 19, 25, 31 },
               { 17, 8, 11, 21, 15, 0, 9 }, { 2, 1, 3, 0, 10, 2, 4 } };
       String playes[] = { "tim", "dora", "cat", "sul", "top" };

       System.out.printf("averagePPG: %.2f ", averagePPG(scores, 1));
       System.out.println("singleGameScore :" + singleGameScore(scores, 0));
       System.out.printf("averageGameScore:%.2f ",averageGameScore(scores));
       System.out.println("singleGameTopScoringplayer:"+playes[singleGameTopScoringplayer(scores, 2)]);

   }

   /**
   * return the average points per game of player p, based on the data in the
   * array scores
   *
   * @param scores
   * @param p
   * @return
   */
   public static double averagePPG(int[][] scores, int p) {

       double sum = 0;
       for (int i = 0; i < scores[p].length; i++) {
           sum += scores[p][i];

       }

       return sum / (double) scores[p].length;
   }

   /**
   * return the total points scored (by entire team) in game g
   *
   * @param scores
   * @param g
   * @return
   */
   public static int singleGameScore(int[][] scores, int g) {

       int points = 0;
       for (int i = 0; i < scores.length; i++) {
           points += scores[i][g];
       }

       return points;
   }

   /**
   * return the average total points scored (by entitr team) per game
   *
   * @param scores
   * @return
   */
   public static double averageGameScore(int[][] scores) {

       int points = 0;
       for (int g = 0; g < scores.length; g++) {
           points += singleGameScore(scores, g);

       }

       return (double) points / (double) scores.length;
   }

   /**
   * return the index of highest scoring player in game g based on data
   *
   * @param scores
   * @param g
   * @return
   */
   public static int singleGameTopScoringplayer(int[][] scores, int g) {

       int points = scores[0][g];
       int index = 0;

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

           if (points < scores[i][g]) {
               points = scores[i][g];
               index = i;
           }
       }

       return index;
   }
}

OUTPUT:

averagePPG: 11.14
singleGameScore :85
averageGameScore:76.60
singleGameTopScoringplayer:cat