Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Challenge 2: Implementing a Sports Team!

Sumit Rawal answered on May 17, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • Solution Review 2: Implementing a Sports Team!

  • Challenge 2: Implementing a Sports Team!

    0

    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. 

    Popularity 1/10 Helpfulness 1/10 Language typescript
    Source: Grepper
    Tags: typescript
    Link to this answer
    Share Copy Link
    Contributed on May 17 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.