0

I have to write a program that keeps the statistics for a basketball team of 10 players. The statistics are shots attempted, made percentage; free throws attempted, made percentage; offensive and defensive rebounds; assists; turnovers and total points. They need to put into parallel arrays. I am attempting to modify a golf score card program but am having problems with figuring out the arrays. The statistics will be entered in using a txt file in the following format:

10 //this being the number of players

1  //this being player 1
20 //shots attempt
15 //shots made
4  //free throws attempt
3  //free throws made
2  //off rebound
2  //def rebound
5  //assists
2  //turnovers
18 //total points

2  //and so on for 10 players

I can modify the txt file if needed

The following is my attempt so far at modifying the golf score card:

    import java.util.Scanner;
    import java.io.*;

    public class BasketballScoreCard {
    private int[] player;
    private int[][] scores;

        /////////////////////////////////////////////////////////////////
        // Instantiate and read golf scores from a text file
        public BasketballScoreCard(String fileName) throws IOException {
            // Open the file
            Scanner fileReader = new Scanner(new File(fileName));

            // Read the number of days
            int numPlayer = fileReader.nextInt();

            // Instantiate dates and dailyScores
            player = new int[numPlayer];
            scores = new int[numPlayer][18];

            // Read the scores for each day
            //   Date (yyyymmdd), followed by 18 scores
            for (int i = 0; i < numPlayer; i++){
            player[i] = fileReader.nextInt() ;
            for (int j = 0; j < 18; j++)
            scores[i][j] = fileReader.nextInt();
        }

        // Close the file     
        fileReader.close();
    }   


    /////////////////////////////////////////////////////////////////
    // Return a string with one line per day.
    // Each line consists of a date and 18 scores
public String toString(){
    String str = "";
    for (int i = 0; i < player.length; i++){
    str += "Player: " + player[i] + " \nScores:";
    for (int j = 0; j < 18; j++)
        str += " " + scores[i][j];
    str += "\n";
    }
    return str;
}   

    /////////////////////////////////////////////////////////////////
    // Return a string with two lines.
    // The first line contains the date and scores for the best day
    // The second line contains the date and scores for the worst day
public String highLowDays(){
        // Assume that the first day is the best and worst
    int indexLow = 0;
    int indexHigh = 0;
    int lowTotal = dayTotal(0);
    int highTotal = dayTotal(0);

    // Now consider the remaining days
    for (int i = 1; i < player.length; i++){
    int todayTotal = dayTotal(i);
    if (todayTotal < lowTotal){
        indexLow = i;
        lowTotal = todayTotal;
    }else if (todayTotal > highTotal){
        indexHigh = i;
        highTotal = todayTotal;
    }
        }

    // Format the return string
    String str = "";
    str += "The best day:  " + player[indexLow] + " score: " + lowTotal + "\n";
    str += "The worst day: " + player[indexHigh] + " score: " + highTotal + "\n";

    return str;
}

    // Return the total for the indicated day
private int dayTotal (int i){
    int total = 0;
    for (int j = 0 ; j < 18; j++)
    total += scores[i][j];
    return total;
}

    /////////////////////////////////////////////////////////////////
    // Return a string with two lines.
    // The first line indicates the hole with the lowest average
    // The second line indicates the hole with the highest average
   public String bestWorstHoles(){
    String str = "";

         return str;
}

// Return the average for the indicated hole
private double holeAverage (int j){
    int numPlayer = player.length;
    double average = 0;
    for (int i = 0 ; i < numPlayer; i++)
    average += scores[i][j];
    return average / numPlayer;
    }
    }

I don't seem to understand if I need to add one array for each stat or use one array for every stat. If I need to to use one array for each stat, how do I bring in the information from the text file to each separate array then?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
VinceCat
  • 25
  • 3
  • 14

0 Answers0