Problem statement
You have to implement 3 classes, School, Team, and Player, such that an instance of a School should contain instances of Team objects. Similarly, a Team object can contain instances of Player class.
Consider this diagram for clarification:
School, Team, Player: Class Representation
You have to implement a School class containing a list of Team objects and a Team class comprising a list of Player objects.
Task 1
The Player class should have three properties that will be set using an initializer:
ID
name
teamName
Task 2
The Team class will have two properties that will be set using an initializer:
name
players: a list with player class objects in it
It will have two methods:
addPlayer(), which will add new player objects in the players list
getNumberOfPlayers(), which will return the total number of players in the players list
Task 3
The School class will contain two properties that will be set using an initializer:
teams, a list of team class objects
name
It will have two methods:
addTeam, which will add new team objects in the teams list
getTotalPlayersInSchool(), which will count the total players in all of the teams in the School and return the count
So, your school should have these players in their respective teams:
Player ID’s Player Names Teams
1 Harris Red
2 Carol Red
1 Johnny Blue
2 Sarah Blue
Coding exercise
First, take a close look, and then, design a step-by-step algorithm before trying the implementation. This problem is designed for your practice, so initially, try to solve it on your own. If you get stuck, you can always refer to the solution provided in the next lesson.