previous | index | next

Class Diagrams

Consider the following classes for representing basketball players:

public class Player implements Comparable<Player> {
    public Player(String name, double ppg) {
	this.name = name;
	this.ppg = ppg;
    }
    public String toString() {
	return name + "  " + ppg;
    }
    public int compareTo(Player other) {
	if ( ppg < other.ppg ) return 1;
	if ( ppg > other.ppg ) return -1;
	return 0;
    }
    private String name;
    private double ppg;  
}
public class PlayerTest {
    public static void main(String[] args) {
	ArrayList<Player> players = new ArrayList<Player>();
	players.add(new Player("Lebron James", 30.2));
	players.add(new Player("Kevin Garnett", 21.3));
	players.add(new Player("Kobe Bryant", 33.4));
	for (Player player : players) {
	    System.out.println(player);
	}
	Collections.sort(players);
	System.out.println();
	for (Player player : players) {
	    System.out.println(player);
	}
    }
}

Draw a class diagram showing the relationships of all types involved. The types are shown in red.


previous | index | next