Study Guide for Exam 2, Wed Nov 6, 2002 Topics: Chapter 3: you'll still need to know about basic while and for loops. Chapter 4: 4.1, on classes, is important 4.2 is on methods (functions). This was on exam 1; it may also be on exam 2. 4.3: overloading. We've used it, but it's not important as a topic itself. 4.4: A few examples of complex programs broken down into pieces. 4.5: Object relationships: this won't be on the exam. 4.6: applets: won't be on the exam. 4.7: graphical stuff: won't be on the exam. Chapter 5: 5.0: references: this is important 5.1: static: the idea is important, but won't be on the exam directly. 5.2: wrapper classes, like Integer for int. More a source of examples of references than an important thing itself. 5.3: There might be a question involving *use* of the Keyboard class. 5.4: nested classes: a useful technique, but not conceptually important. 5.5: interfaces. Know what they are, but you won't have to define one. You might have to *use* one, though. 5.6, 5.7: more graphical interface stuff. Won't be on the exam at all. Chapter 6, Arrays: 6.0: array basics 6.1: arrays of objects 6.2: sorting. Don't worry about knowing specific algorithms. But know what you have to do to sort objects, etc. 6.3: 2-D arrays. Won't be on the exam. 6.4: ArrayLists. An ArrayList might be on the exam. 6.5, 6.6: omit ====================== Sample end-of-chapter exercises There really aren't any good end-of-chapter exercises on writing classes in chapter 4, although 4.1-4.16 are all about writing useful class methods (most of them static, in that they don't refer to member variables). THe same goes for chapter 5, although exercise 5.2 on page 314 might be worth looking at. Almost all the other end-of-chapter exercises in chapter 5 are about interface definitions, which we're not really doing. For chapter 6, look at 6.2 through 6.7 on page 374. ====================== Sample questions 1. Write a loop to find the product of all the numbers in an array A of type double. For example, if A contains [1.2, 2.0, 2.5], then your loop should end with 6.0 in a suitable variable. 2. Write a function to find the product in part 1. 3. Write a class Counter with two methods: value(), to get the current integer value stored internally, and increment(), to increment that value. Give your class a constructor, that explicitly initializes the counter so that value() initially returns the value 0. 4. Consider the following array a: +---+---+---+---+---+---+---+---+---+ | 3 | 4 | 2 | 5 | 7 | 1 | 0 | 8 | 6 | +---+---+---+---+---+---+---+---+---+ Give: a[1] a[ a[1] ] a[ a[a[1]+1] ] 5. Consider the following class: class Foo { private int _x; public Foo(int x) {_x = x;} public int get() {return _x;} public void set(int x) {_x = x}; public void inc() {_x++;} } Give the output: int x=7, y=2; Foo a = new Foo(3), b = new Foo(5), c; Foo[] v = new Foo[5]; x = y; y++; System.out.println("x=" + x + " y=" + y); a = b; b.set(b.get()+5); a.inc(); System.out.println("a.get()=" + a.get() + " b.get()=" + b.get()); c = new Foo(0); int i; for (i = 0; i