import java.util.ArrayList; public class League { private String name; private ArrayList teams; public League(String n) { this.name = n; this.teams = new ArrayList(); // Doesn’t make any Team objects } // This specifies the appearance of the League public String toString() { return ("The " + this.name + " league"); } // Add the given team to the League public void addTeam(Team t) { teams.add(t); } // List all of the teams in the League public void showTeams() { for (Team t: teams) { System.out.println(t); } } // Record a win and a loss in the league public void recordWinAndLoss(Team winner, Team loser) { if ((winner != null) && (loser != null)) { winner.recordWin(); loser.recordLoss(); } } // Record a tie in the league public void recordTie(Team teamA, Team teamB) { if ((teamA != null) && (teamB != null)) { teamA.recordTie(); teamB.recordTie(); } } // Find the team with the given name private Team teamWithName(String nameToLookFor) { for (Team t: teams) if (t.getName().equals(nameToLookFor)) return t; return null; } // Record a win and a loss in the league based on team names public void recordWinAndLoss(String winnerName, String loserName) { this.recordWinAndLoss(this.teamWithName(winnerName), this.teamWithName(loserName)); } // Record a tie in the league based on team names public void recordTie(String teamAName, String teamBName) { this.recordTie(this.teamWithName(teamAName), this.teamWithName(teamBName)); } // Find the total number of games played in the league public int totalGamesPlayed() { int total = 0; for (Team t: teams) total += t.gamesPlayed(); return total/2; } // Return the first place team public Team firstPlaceTeam() { Team teamWithMostPoints; if (teams.size() == 0) return null; teamWithMostPoints = teams.get(0); for (Team t: teams) { if (t.totalPoints() > teamWithMostPoints.totalPoints()) teamWithMostPoints = t; } return teamWithMostPoints; } // Return the last place team public Team lastPlaceTeam() { Team teamWithMostPoints; if (teams.size() == 0) return null; teamWithMostPoints = teams.get(0); for (Team t: teams) { if (t.totalPoints() < teamWithMostPoints.totalPoints()) teamWithMostPoints = t; } return teamWithMostPoints; } // Return a list of all undefeated teams public ArrayList undefeatedTeams() { ArrayList undefeated = new ArrayList(); for (Team t: teams) { if (t.getLosses() == 0) undefeated.add(t); } return undefeated; } // Remove all teams that have not won any games public void removeLosingTeams() { for (int i=0; i