import java.util.*;
public class ContestLocations {
public static void main(String[] args) {
ContestList contestList = new ContestList();
// Add some Contests.
contestList.addContest(new Contest("sing", "12 Mar", "Dallas, TX"));
contestList.addContest(new Contest("draw", "19 Mar", "Tampa, FL"));
contestList.addContest(new Contest("ride", "22 Mar", "Stockton, CA"));
contestList.addContest(new Contest("sail", "22 Mar", "Tampa, FL"));
contestList.addContest(new Contest("ride", "29 Mar", "Cheyenne, WY"));
contestList.addContest(new Contest("sail", "30 Mar", "Santa Cruz, CA"));
// Get the locations of the contests.
List<String> locs = contestList.getLocations();
System.out.println("locs = " + locs);
}
}
class Contest {
String name;
String date;
String location;
Contest(String name, String date, String location) {
this.name = name;
this.date = date;
this.location = location;
}
public String getLocation() { return location; }
}
class ContestList {
List<Contest> list = new ArrayList<Contest>();
public void addContest(Contest contest) {
list.add(contest);
}
public List<String> getLocations() {
List<String> allLocations = new ArrayList<String>();
for(int j = 0; j < list.size(); j++) {
Contest contest = (Contest)list.get(j);
String location = contest.getLocation();
// Avoid duplicate locations.
if(!allLocations.contains(location)) {
allLocations.add(location);
}
}
return allLocations;
}
}