CS115 lecture notes, Spring 1999 Week 8, Monday Hand back exams and go over them. QUIZ WEDNESDAY. Things to review: 1) two types of types object types begin with capital letters you can invoke methods ON members of object types primitive types begin with lower case letters. 2) infinite loops and infinite recursion 3) recursive definitions and recursive methods using pseudocode to describe algorithms The accumulator pattern ----------------------- Add up a series of terms... public static int accumulate (int n) { int i = 0; int total = 0; while (i < n) { total = total + (something that depends on i) i = i+1; } return total; } The counter pattern ------------------- Count how many times something happens... String fruit = "banana"; int count = 0; int index = fruit.indexOf ('a'); while (index != -1) { count = count + 1; index = fruit.indexOf ('a', index+1); } System.out.println (count); In the first example, I "traversed" the integers from 0 to n. In the second case, I traversed the letters in a String. But the counting/accumulating pattern is similar in both cases. In fact, you can think of a counter as a special kind of accumulator. Four kinds of methods --------------------- 1) void, fruitful (when you invoke a fruitful method, don't forget to do something with the result) 2) methods you invoke on objects = Object methods methods you just invoke = Class methods g.drawOval, System.out.println ... factorial, paintShirt Math.cos It is probably not clear at this point why Math.cos is a class method and System.out.println is an object method. That's ok.