ICS-22 Collections Programming Exam
Overview
Overview of What to Know
For problems in this exam suite, you must be familiar with the Java interfaces
for OrderedCollection, List, Set, Map,
Iterator, Comparable and Comparator.
In addition, you must understand the use of the classes ArrayQueue,
ArrayStack, ArrayPriorityQueue, ArrayList,
HashSet, HashMap, 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 the 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 (note that you can -but do not have to- use
Generic Collection Classes to avoid explicit casting).
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 all tokens in 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
- Use exactly the required collection classes (and possibly the specified
arrays) in the problem statement.
- 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 then 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.
I reserve the right to deduct up to total of 10% for "ugly" code; correctly
working code is guaranteed to receive at least 90% of the total points.
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 files 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 a small number of lines of code (<= 50, 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)