| CIT 594 Final Exam Spring 2005, Dave Matuszek |
Name _______________________________________
|
Please keep all answers short and to the point.
<pair>, where a
"pair" consists of two items, separated by a comma, and surrounded
by parentheses; an "item" can be either a number or another pair.
For example, (5, (13, 3)) . Assume that
<number> has already been defined.boolean pair() method to recognize a "pair"
as defined in the previous question. You can assume the existence of other
methods to recognize the various pieces of a "pair."enum named WEEKDAY,
enumerating the seven days of the week, with boolean method isWorkDay().
isWorkDay() should return true for all days except
Saturday and Sunday. Use proper capitalization (days of the week should be
all caps). if
(myList instanceof ArrayList<Integer>) {...} Person, where each Person
has a String name instance variable. You want to create a set
of Persons, sorted by name (and never sorted any
other way). Person.Person
class to keep the set of Persons in sorted order.hashCode() (such as String),
what range of values is returned by the hashCode() method?
,
tell in what order the nodes would be visited by each of the following techniques:
|
|
||||||||||||||||||||||||
K characters. You have a message
that is N characters long. In each of the following parts, describe
briefly (1) how to do the required task, and (2) how long it
will take to do it (use Big-O notation). N-character message.5 10 ...,
a player may either take the 5, or give the 5 to the opponent and take the
10.) The object is to collect the most money. int count = 0;
void countNodes(BinaryTree b) {
if (b == null) return;
count++;
countNodes(b.getLeftChild());
countNodes(b.getRightChild());
}
Fraction(int numerator, int denominator)
which should throw an IllegalArgumentException if denominator
== 0 . Write a JUnit method to test that it throws the exception
correctly.Couples ADT to represent a set of
married couples. The only accessor method will be Person getSpouse(Person p)
which, given one person in a couple, returns the other person. Your operations
should make it possible to create any Couples, and to transform
any Couples into any other Couples. Provide a necessary
and sufficient set of constructors and methods (no convenience methods) to
achieve this. Do not tell what each method does; just choose self-explanatory
names for your methods.getSpouse method (from the previous question) in linear time.