| CIT594 Midterm Exam Spring 2006 |
Name_________________________________________ |
Please keep all your answers short and to the point. Do not provide extra information that was not asked for.
| You want to do the following: | What interfaces, if any, must your Employee class implement? | What methods must your Employee class implement? (Show the complete signature.) |
|---|---|---|
|
Use Employee objects as keys in a HashMap |
||
| Keep a SortedSet of Employee
objects |
||
| Be able to sort Employee objects by either
their name field or their EmployeeId field |
| uu | uw | w | |
| ux | uxy | wy | |
| uxx | uxwy | wyyy |
public boolean term() {
if (!term()) return false;
while (multiplyOperator()) {
if (!term()) error("No term after '+' or '-'");
}
return true;
}
![]() |
|
int findFive(final int ARRAY_SIZE, int[] array) {
for (int i = 0; i < ARRAY_SIZE; i++) {
if (array[i] == 5) return i;
}
return -1;
}
int log2(int n) {
int result = 0;
int power = 1;
while (power < n) {
result++;
power = 2 * power;
}
return result;
}
| (best) |
|
(worst)
|
| Collection | |
|---|---|
| Set | |
| SortedSet | |
| List | |
| Map | |
| SortedMap | |
| Bubble sort |
|
|---|---|
| Insertion sort |
|
| Selection sort |
|
|
Schlemiel gets a job as a street painter, painting the dotted lines down the middle of the road. On the first day he takes a can of paint out to the road and finishes 300 yards of the road. "That's pretty good!" says his boss, "you're a fast worker!" and pays him a kopeck. The next day Schlemiel only gets 150 yards done. "Well, that's not nearly as good as yesterday, but you're still a fast worker. 150 yards is respectable," and pays him a kopeck. The next day Schlemiel lpaints 30 yards of the road. "Only 30!" shouts his boss. "That's unacceptable! On the first day you did ten times that much work! What's going on?" "I can't help it," says Schlemiel. "Every day I get farther and farther away from the paint can!" |