PlayerGameStats
Challenge yourself to construct the PlayerGameStats class and populate the relevant stats.
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.
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 into 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, which means 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, our primary task is to create and associate each player statistics with a game.
Let’s get started.
Properties
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_rebounds
: The total count of offensive rebounds by a player in a game.defensive_rebounds
: The total count of defensive rebounds by a player in a game.assists
: The number of assists a player provides in a game. ...