1
+ package exercise7
2
+
3
+ internal interface LeagueApi {
4
+ /* *
5
+ * Represents a list of teams participating in a league.
6
+ *
7
+ * @property teams The list of teams.
8
+ */
9
+ val teams: List <Team >
10
+ /* *
11
+ * Returns the list of [LeagueTableEntry] where every team result of the season is aggregated.
12
+ * The League table is sorted by points descending. If more than one team has the same number of points,
13
+ * sort them by goal difference.
14
+ */
15
+ val leagueTable: List <LeagueTableEntry >
16
+
17
+ /* *
18
+ * Returns the team that won the league.
19
+ *
20
+ * @property leagueWinner The team that won the league.
21
+ * The Team won the league if it has the most points in the league.
22
+ * If two or more teams have a same number of points, the team with the best goal difference among them wins the league.
23
+ */
24
+ val leagueWinner: Team
25
+
26
+ /* *
27
+ * Returns the team with the most wins in the league.
28
+ */
29
+ val teamWithMostWins: Team
30
+
31
+ /* *
32
+ * Returns the team with the most draws in the league.
33
+ */
34
+ val teamWithMostDraws: Team
35
+
36
+ /* *
37
+ * Returns the team with the most loses in a league.
38
+ */
39
+ val teamWithMostLoses: Team
40
+
41
+ /* *
42
+ * Returns a team in the league with the best goal difference.
43
+ */
44
+ val teamWithBestGoalDifference: Team
45
+
46
+ /* *
47
+ * Calculates the teams with the best defense based on the number of goals they have conceded.
48
+ *
49
+ * @param numOfTeams The number of teams to include in the result.
50
+ * @return The list of teams with the best defense, sorted in ascending order based on the number of goals conceded.
51
+ */
52
+ fun teamsWithBestDefence (numOfTeams : Int ): List <Team >
53
+
54
+ /* *
55
+ * Calculates the teams with the best offense based on the number of goals they have scored.
56
+ *
57
+ * @param numOfTeams The number of teams to include in the result.
58
+ * @return The list of teams with the best offense, sorted in descending order based on the number of goals scored.
59
+ */
60
+ fun teamsWithBestOffense (numOfTeams : Int ): List <Team >
61
+
62
+ /* *
63
+ * Calculates the number of goals that a team has scored against a specific opponent team.
64
+ *
65
+ * @param scorerTeam The team that has scored the goals.
66
+ * @param against The opponent team.
67
+ * @return The number of goals that the scorer team has scored against the opponent team.
68
+ */
69
+ fun numOfGoalsTeamScoredAgainst (scorerTeam : Team , against : Team ): Int
70
+
71
+ /* *
72
+ * Calculates the number of goals that a conceded team has conceded against a specific opponent team.
73
+ *
74
+ * @param concededTeam The team that has conceded the goals.
75
+ * @param against The opponent team.
76
+ * @return The number of goals that the scorer team has conceded against the opponent team.
77
+ */
78
+ fun numOfGoalsTeamConcededAgainst (concededTeam : Team , against : Team ): Int
79
+
80
+ /* *
81
+ * Display the league table after fixture with [fixtureId] was played.
82
+ * Table should be displayed in the same format as in a method [displayLeagueTable].
83
+ */
84
+ fun displayLeagueTableAtFixture (fixtureId : Int )
85
+
86
+ /* *
87
+ * Display league table with all fixtures are played.
88
+ * League table should be printed in the following format:
89
+ * ```
90
+ * P | Team name | Games Played | Wins | Draws | Loses | GS | GC | Total Points
91
+ * 1. Manchester City 38 27 5 6 83 32 86
92
+ * 2. Manchester Utd 38 21 11 6 73 44 74
93
+ * 3. Liverpool 38 20 9 9 68 42 69
94
+ * 4. Chelsea 38 19 10 9 58 36 67
95
+ * 5. Leicester City 38 20 6 12 68 50 66
96
+ * 6. West Ham 38 19 8 11 62 47 65
97
+ * 7. Tottenham 38 18 8 12 68 45 62
98
+ * 8. Arsenal 38 18 7 13 55 39 61
99
+ * 9. Leeds United 38 18 5 15 62 54 59
100
+ * 10. Everton 38 17 8 13 47 48 59
101
+ * 11. Aston Villa 38 16 7 15 55 46 55
102
+ * 12. Newcastle Utd 38 12 9 17 46 62 45
103
+ * 13. Wolves 38 12 9 17 36 52 45
104
+ * 14. Crystal Palace 38 12 8 18 41 66 44
105
+ * 15. Southampton 38 12 7 19 47 68 43
106
+ * 16. Brighton 38 9 14 15 40 46 41
107
+ * 17. Burnley 38 10 9 19 33 55 39
108
+ * 18. Fulham 38 5 13 20 27 53 28
109
+ * 19. West Brom 38 5 11 22 35 76 26
110
+ * 20. Sheffield Utd 38 7 2 29 20 63 23
111
+ * ```
112
+ * where columns are ordered as following:
113
+ * `P` - is a position on the board
114
+ * `Team name` - name of the team
115
+ * `Games Played` - total games played by team
116
+ * `Wins` - total wins by team
117
+ * `Draws` - total draws by team
118
+ * `Loses` - total loses by team
119
+ * `GS` - total goals scored by team
120
+ * `GC` - total goals conceded by team
121
+ * `Total Points` - total points won by team
122
+ */
123
+ fun displayLeagueTable ()
124
+ }
125
+
126
+ /* *
127
+ * Task: Implement class [League] that implements [LeagueApi] interface. Class [League] has two properties:
128
+ * @property teams - teams in the League.
129
+ * @property fixtures - League fixtures with a set of games played that round.
130
+ *
131
+ * Task: In class init block, validate parameters of the class.
132
+ * Parameters are valid if all the fixtures contain only teams from the [teams] list,
133
+ * and [teams] are all mentioned in the [fixtures] list.
134
+ */
135
+
136
+ // TODO Implement League class that implements LeagueApi interface.
0 commit comments