15-200 Collection Programming Exam
Overview

Overview of What to Know

For problems in this exam suite, you must be familiar with the Java interfaces for Set, Map, List, Iterator, and Comparable (you may use the Comparator interface as well). In addition, you must understand the use of the classes HashSet, HashMap, ArrayList, and LinkedList, which implement these collections, as well as StringTokenizer, including its two-parameter constructor whose signature is (String,String). You must also understand the use of the static sort methods defined in the Arrays and Collections classes, which use the Comparable (and optionally Comparator) interface: to use the Arrays class you must be able to convert between collections and arrays. Finally, you should be familiar with casting generic (Object) references, when necessary. You must not use either the TreeSet or TreeMap classes when solving these problems.

The following line of code prompts the user for a file name and stores into allLines an iterator whose next method is used to produce a String containing the next line in the file. When necessary, tokens in each line can be extracted sequentially by using an object constructed from the StringTokenizer class. All file input on the exam is handled in this way.

  Iterator allLines = ExamIO.readFile("Enter a file name");
This code is also available using generics, as
  Iterator<String> allLines = ExamIO.readFile("Enter a file name");

Qualifications

For full credit on this exam you must (a) use exactly the required collection classes (and possibly the specified arrays) in the problem statement and (b) use no other collections or arrays. By following this guideline, your solution should be compact, elegant, and efficient. Of course, your program should be general: it must work on the tested data and should work on other similar data as well.

Programs typically read one file of data first, and use it to construct a large data structure. Then they use this data structure to perform some task. Each of these two parts is worth 50% of the total points for this problem. This is the only partial credit allowed for this exam: unless a part works completely, no credit is awarded for that part.

You can read the Javadoc for Sun's API for details on the relevant interfaces and classes used in these problems.

You may use Java 1.4-style collections (with no generics) or Java 1.5-style collections (with generics). You can use or ignore Java 1.5-style for loops. Note that all input file will be correct as specified: you do not have to check for bad values in input files.

Code

You can write all your code in main or optionally write static methods. Optimal code in this context is code that you can write and debug quickly. Most programs can be written in 50 lines of code (not counting imports, blank lines, nor lines with only opening/closing braces on them). This number is offered only as a ball-park estimate, to give you some idea of how much code you should be writing: a program will NOT be graded on its size. But, if you are grossly exceeding this number of lines, you might be overlooking some way to simplify your code and might not have enough time to write/debug that much code and still solve the other problems on the exam.

Problem Statement (Including Input and Output)