import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;

    // Implement only the required methods of AbstractTableModel.
class SimpleLeagueTableModel extends AbstractTableModel {
    public SimpleLeagueTableModel(League l){
        league = l;
    }

        // Implementations of the abstract methods.

    public int getRowCount(){
        return getTeams().length;
    }

    public int getColumnCount(){
        return numColumns;
    }

    public Object getValueAt(int row, int col){
        final TeamDetails[] teams = getTeams();
        final int numTeams = teams.length;
        if((row >= 0) && (row < numTeams) && (col >= 0) && (col < numColumns)){
            final TeamDetails team = teams[row];
            switch(col){
                case TEAM:
                    return team.getName();
                case COACH:
                    return team.getCoach();
                case VENUE:
                    return team.getVenue();
                case POINTS:
                    return new Integer(team.getPoints());
                default:
                    return null;
            }
        }
        else{
            return null;
        }
    }

    protected TeamDetails[] getTeams(){
        return getLeague().getTeams();
    }

    protected League getLeague(){
        return league;
    }

    // This information is closely tied to the implementation of
    // TeamDetails.
    private static final int numColumns = 4;
    private static final int TEAM = 0, COACH = 1, VENUE = 2, POINTS = 3;

    // The team details.
    private final League league;
}
