PlayerGameStats

Challenge yourself to construct the PlayerGameStats class and populate the stats of all relevant players, teams, and games.

As previously noted, we deferred the creation of the PlayerGameStats class and opted to construct the Game class first. Now is the time to proceed with building this class.

Press + to interact
UML diagram highlighting the development focus on the PlayerGameStats class and it’s relationship with the Game class
UML diagram highlighting the development focus on the PlayerGameStats class and it’s relationship with the Game class

It’s important to reiterate that upon completing this class, we must also make updates to the Game class. Therefore, both tasks will be addressed in this step.

Since we constructed the Game class in the last lesson, it’s time to go for the PlayerGameStats class and build it. If we look at the UML diagram above, we can observe that the Game class requires the PlayerGameStats class to complete its functionality as the PlayerGameStats contains the stats of the games. This means that to construct the Game class completely for our project, we require the PlayerGameStats component as well.

Once again, keep in mind that the Main class acts as the client and facilitates the construction and testing of our project. Therefore, we incorporate this functionality into the Main class, along with the code for the PlayerGameStats.

In this class, the primary task is to create and associate each player’s statistics with a game.

Let’s get started.

Data members

  • Game: The game to which these statistics belong

  • Player: The player with whom these statistics are associated

  • Field goals: The total number of field goals a player scored in a game

  • Three points: The total number of three-point shots a player made in a game

  • Free throws: The number of free throws a player scores in a game

  • Offensive ...