    // Maintain an array of TeamDetails object, initialised at
    // construction. Provide methods to print the league, add points
    // to a team (given its name), and return a TeamDetails given
    // a team name. 
class League {
        // Make a copy of the team list.
    public League(TeamDetails[] teamList){
        setTeams(teamList);
    }

        // Print out the name of each team in the league with the
        // number of points it has, on a single line.
    public void print(){
        final TeamDetails[] teamList = getTeams();
        final int numTeams = teamList.length;
        for(int i = 0; i < numTeams; i++){
            final TeamDetails team = teamList[i];
            System.out.println(team.getName()+" = "+team.getPoints());
        }
    }

        // Add the given number of points to the team whose name
        // matches teamName.
    public void addPoints(String teamName, int points){
        TeamDetails team = findTeam(teamName);
        if(team != null){
            team.setPoints(team.getPoints()+points);
        }
        else{
            System.err.println("Team: "+teamName+" was not found.");
        }
    }

        // Find the TeamDetails with the given name. The search
        // is case insensitive. Return null if no match is found.
    public TeamDetails findTeam(String teamName){
        final TeamDetails[] teamList = getTeams();
        final int numTeams = teamList.length;
        for(int i = 0; i < numTeams; i++){
            if(teamName.equalsIgnoreCase(teamList[i].getName())){
                return teamList[i];
            }
        }
        return null;
    }

        // Clear the points for each team in the league.
    public void clearPoints(){
        final TeamDetails[] teamList = getTeams();
        final int numTeams = teamList.length;
        for(int i = 0; i < numTeams; i++){
            teamList[i].setPoints(0);
        }
    }

    public TeamDetails[] getTeams(){
        return teams;
    }

        // Take a copy of the array's data.
    private void setTeams(TeamDetails[] t){
        if(t != null){
            final int num = t.length;
            teams = new TeamDetails[num];
            System.arraycopy(t,0,teams,0,num);
        }
    }

    // The details are set from the constructor.
    private TeamDetails[] teams;
}
