Question 2: Modelling and Processing Files and Objects The world cup is currently under way, but the organisers have been very forgetful. They need a system to help them keep track of the progress of the tournament and determine which teams have won in the groups and which games should be played next.
a. Define a class named FootballTeam which implements the Team interface provided. This class will be used to keep track of the progress of teams in the group stages of the tournament. This means we need to be able to remember or calculate all of the relevant statistics. The methods in the FootballTeam class should be implemented based on the following descriptions: •public String getName() - Returns the name of the team •public int getWins() - Returns the number of games the team has won •public int getLosses() - Returns the number of games the team has lost •public int getDraws() - Returns the number of games the team has drawn •public int getPoints() - Returns the number of points the team has scored (3 for a win, 1 for a draw and 0 for a loss) •public int getGoalsFor() - Returns the number of goals that this team has scored in all of their games •public int getGoalsAgainst() - Returns the number of goals that other teams have scored when playing this team •public int addGame(Game g) - Adds the result of a game that was played by this team.1 In order to function in the testing system, you must also add a constructor with the following signature: public FootballTeam(String name).
referenceName – 可以是一个 Byte, Double, Integer, Float, Long 或 Short 类型的参数。
返回值
如果指定的数与参数相等返回 0。
如果指定的数小于参数返回 -1。
如果指定的数大于参数返回 1。
b. Define a class named FootballGame which implements the Game interface provided. This class will be used to remember the statistics of a single game in the tournament between two teams. The methods in the FootballGame class should be implemented based on the following descriptions: •public Result getResult(Team team) - Returns the result of the game (Result.WIN, Result.LOSS, or result.DRAW) for the team passed as a parameter •public int getGoalsFor(Team team) - Returns the number of goals that were scored by the team passed as a parameter •public int getGoalsAgainst(Team team) - Returns the number of goals that were against by the team passed as a parameter For all of these methods, if the team parameter that is passed does not match either of the teams in the game then an IllegalArgumentException should be thrown.
@Override publicintgetGoalsFor(Team a) { if (a.equals(teamA)) { return scoreA; } else { return scoreB; } }
@Override publicintgetGoalsAgainst(Team a) { if (a.equals(teamA)) { return scoreB; } else { return scoreA; } } }
c. Define a class named WorldCupGroup which implements the Group interface provided. This class will be used to determine which teams can progress to the next round of the tournament as well as producing the table of results. The methods in the WorldCupGroup class should be implemented based on the following descriptions: •public Team getWinner() - Returns the team object of the team that came first in the group •public Team getRunnerUp() - Returns the team object of the team that came second in the group •public String getTable() - Returns a string containing the current table for the group. The getTable method should have output in the following format. The group name should be on the first line, the column headers should be on the second line, and the teams and their statistics should be on the remaining lines. An example of the output is given here:
In this the following abbreviations are made: •W - For the number of games the team has won •D - For the number of games the team has drawn •L - For the number of games the team has lost •F - For the number of goals the team has scored •A - For the number of goals that have been scored against this team •P - For the number of points the team has scored The teams should be primarily ordered from largest to smallest by points. If teams are equal on points, then they should be secondarily ordered by goal difference (F - A). Finally, if all of these are equal then they should be orders based on their names. All of the methods in this class rely on the ability to correctly order the teams in this way. Consider what approach you will use to sort the objects into the correct order. In order to function in the testing system, you must also add a constructor with the following signature: public WorldCupGroup(String groupName, Team a, Team b, Team c, Team d)