import java.util.*; import java.io.*; /** * Create cycling groups. */ public class RidingGroup implements Iterable> { private List> groups; /** Constructor for Riding Group */ public RidingGroup() { // initialize the category map groups = new ArrayList>(); // Create an entry in the map for each skill for (Distance dist: Distance.values()) { // Each group is associated with a set of cyclist names groups.add(new HashSet()); } } /** Read the cyclist data from an input stream and create the list. * @return List of cyclists from whom to form groups. */ public void load(Scanner input) { // Read all input while(input.hasNext()) { //the first token will be the name String name = input.next(); Distance distance = Distance.valueOf(input.next()); // categorize the riders by distance groups.get(distance.ordinal()).add(name); } } /** Accessor to an iterator over the groups */ public Iterator> iterator() { return groups.iterator(); } /** Local main for testing */ public static void main(String[] args) throws java.io.IOException { // Open standard input for reading the text RidingGroup rg = new RidingGroup(); rg.load(new Scanner(System.in)); //rg.createGroups(list); Iterator> iter = rg.iterator(); for (Distance dist: Distance.values()) { System.out.println(dist); System.out.println(iter.next()); } } } /** Enumerated type for riding distances */ enum Distance { easy, moderate, lengthy, century, centuryplus; }