The material presented in this guide covers the concepts emphasized on the final exam. It is meant to guide students studying and reviewing for the test; it is not guarranteed to be comprehensive. Actual test questions will differ from the examples given here. Students should use this guide in addition to other study activities (like reading the textbook, reviewing completed lab assignments, old quizzes, etc.) Some material here may be updated, so check periodically for changes.
The exam will emphasize Chapters 16-21.
Be sure you understand iteration and arrays thoroughly. While not specifically emphasized, we will still be expected to understand how classes, objects, assignment, conditional execution, inheritance, and polymorphism work. You may be asked to use some of the standard classes that you have used in the labs: Scanner, Random, String, etc., so you should understand how to use them. The Fall 2006 exam consists of two sections:
For example, consider the following code:
int i = 0, j = 50;
while (i < j) {
System.out.println("Loopy");
i++;
j--;
}
How many times does this section of code print the word loopy?
For example, complete the following class. A Summation object is used to compute the sum of all the integers between two values, inclusive. For example,
Summation s = new Summation(10, 15); System.out.println(s.sum());
displays 75, since 10 + 11 + 12 + 13 + 14 + 15 = 75. Complete the sum() method.
public class Summation {
private int begin;
private int end;
public Summation(int b, int e) { begin = b; end = e; }
public int sum() {
}
}
Be able to write a class from scratch given a specification of what that class is to do. For example:
Develop a class named Counter. Counter objects, obviously, can be used to count things. These objects work in a fashion similar to turnstiles that count people entering or leaving a building. A Counter object should:
Completely define the Counter class.
You should be able to write an independent method given some specifications about its behavior. An independent method is a class method that makes no references to class variables (instance variables are automatically off-limits, since class methods cannot access instance variables). An independent method can be copied out of one class and pasted into another and work just fine, because it does not depend on any information in the enclosing class to do its job. This means all information guiding their behavior must be passed in as parameters (or input from the user, as appropriate).
For example, consider the following problem:
Write a method named count() that accepts two parameters:
It should return the number of times the second parameter appears in the array. The method should not modify the contents of the array. For example, if the array a contains the sequence 3, 2, 5, 3, 0, the method call count(a, 3) would return 2, since the element 3 appears twice in the array. Your count() method should do no I/O.
public static int count(int[] a, int x) {
}
Beware! Any problems that state that "the method should do no I/O" means you should not get input from the user nor should you print anything on the screen. In the example above, the client passes in the necessary information via parameters---no Scanner object is are needed. Likewise, the answer is passed back to the client via a return value---no System.out.println() should appear.