CS115 lecture notes, Spring 1999 Week 7, Wednesday EXAM FRIDAY: Chapters 1-6 and up to 7.4 All lecture notes, labs and quizzes are also fair game. Continuation of charAt discussion... index ----- An index is a value or variable that is used to "indicate" one of the elements of a set. In this case the set is the letters in the String. All indixes are integers. An index is one of the "roles" a variable plays (along with loop variable, lower and upper bound, counter and accumulator). Traversing a String ------------------- Write a loop that reads the characters of a String one at a time and prints them. Section 7.3 Break: throw snowballs at passersby. EXAM REVIEW: mechanism and abstraction mechanism abstraction --------- ----------- method implementation method documentation (body) what it does how it works what parameters/return value method invocation method invocation mechanism (high-level view) follow the stack leap of faith iteration tables abstract loop constructs traversal loop variable "goes from a to b" indices Everything in the left column is important to know so that you are aware of how things work. Also, you can _start_ by understanding the mechanism. Eventually, you need to shift your attention to the right. When you read programs, read them abstractly. If nothing else, it lets you read them more quickly. When you write programs, think in terms of abstract problem-solving building-blocks Can you solve the problem by 1) writing a recursive definition and translating it into a recursive Java program? 2) traversing something and counting the number of times something happens? 3) traversing something and accumulating a result? Final thoughts -------------- why do methods exist? parameters are hypothetical -- when you write the method you don't know what they are you have to write something general, that can deal with any parameter values when you invoke the method, that's when the parameters get values. 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, methods you just invoke. g.drawOval, System.out.println ... factorial, paintShirt