Apply the appropriate transformations described in Section 10.4.2 to the associations below. Assume that all associations are bidirectional, but that the aggregation associations do not change after each object has been created. In other words, the creator of each class must be modified so that aggregations are initialized during the creation of each object. Write the source code needed to manage the associations, including class, field, and method declarations, method bodies, and visibility.

What will be an ideal response?


Figures 10-6 through 10-9 depict a sample solution. The constructor of Tournament and Round set the one side of the
aggregation association, removing the need for a setLeague and setTournament method.
```
public class League {
private Set tournaments;
public League() {
tournaments = new HashSet();
}
public Tournament [] getTournaments() {
return (Tournament[])tournaments.toArray();
}
public void addTournament(Tournament t) {
tournaments.add(t);
}
public void removeTournament(Tournament t) {
tournaments.remove(t);
}
}
```
Figure 10-6 Class League.
```
public class Tournament {
private League league;
private Set rounds;
private Set players;
public Tournament(League l) {
rounds = new HashSet();
players = new HashSet();
league = l;
l.addTournament(this);
}
public League getLeague() {
return league;
}
public Round [] getRounds() {
return (Round[])rounds.toArray();
}
public void addRound(Round r) {
rounds.add(r);
}
public void removeRound(Round r) {
rounds.remove(r);
}
public Player [] getPlayers() {
return (Player[])players.toArray();
}
public void addPlayer(Player p) {
if (!players.contains(p)) {
players.add(p);
p.addTournament(this);
}
}
public void removePlayer(Player p) {
if (players.contains(p)) {
players.remove(p);
p.removeTournament(this);
}
}
}
```
Figure 10-7 Sample class Tournament.
```
public class Round {
private Tournament tournament;
public Round(Tournament t) {
tournament = t;
t.addRound(this);
}
public Tournament getTournament() {
return tournament;
}
}
```
Figure 10-8 Class Round.

```
public class Player {
private Set tournaments;
public Player() {
tournaments = new HashSet();
}
public Tournament [] getTournaments() {
return (Tournament[])tournaments.toArray();
}
public void addTournament(Tournament t) {
if (!tournaments.contains(t)) {
tournaments.add(t);
t.addPlayer(this);
}
}
public void removeTournament(Tournament t) {
if (tournaments.contains(t)) {
tournaments.remove(t);
t.removePlayer(this);
}
}
}
```
Figure 10-9 Class Player.

Computer Science & Information Technology

You might also like to view...

__________ between the external paging device and real memory is a system function and thus is transparent to the user.

a. Roll-in and roll-out b. Swapping pages c. Dynamic address translation d. The premise of this question is false.

Computer Science & Information Technology

How many attempts will the binary search make to find the number 28?

Given a table of data with the three elements shown, assume that you are using a binary search routine. 16 49 28 a. Can't be done b. one attempt c. two attempts d. three attempts e. None of the above

Computer Science & Information Technology

A(n) __________ work modifies a copyrighted work but does not substantially change its content or purpose.

A. transformative B. Creative Commons C. copyrighted D. derivative

Computer Science & Information Technology

Symbols may contain compound paths.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology