comp 170 study guide 1 Dordal Exam: Monday, Sept 30, 2002 Last-minute flash: the exam has no applet material on it. Summary of sections covered: Chapter 1: you can skim sections 1.3 and 1.4 at your leisure, on programming and programming languages. This material is not likely to help directly on the exam, although I recommend you look at Figure 1.19 on page 35, the list of java reserved words. Chapter 2: This chapter introduces several fundamentals: variables, expressions, assignment statemetns, and also a few objects such as String, Random, Math, NumberFormat, Graphics, and Applet. The Keyboard class is discussed in this chapter as well, but we have made only incidental use of it so far and using it will not be on the exam. Section 2.2: print and println. Section 2.3: variables, assignment, final Section 2.4: int, double, long, char, boolean Section 2.5: precedence and stuff like that Section 2.6: "creating objects", mostly string examples. Important. There is a nice summary of string "methods" on page 89. Section 2.7: import, and class Random. You do *not* need to worry about import. The "new" operator is covered in this and in 2.6; "new" is important. Section 2.8: classes Math and Keyboard. Skip Keyboard. Section 2.9: NumberFormat and DecimalFormat classes. Skim only; don't worry about the details. Section 2.10: A sample applet, basically Section 2.11: using the Graphics class. See (but don't worry about memorizing!) the table on page 112, and the color chart on 114. Chapter 3: This is the most important chapter, centering on real programming. Section 3.2: if and if-else (and if ... else if ... else...) Section 3.3: switch statement: less important Section 3.4: boolean (true/false) expressions; skim Section 3.5: ++, +=, etc. Know these. Section 3.6: while statement, the most important part of chapter 3! Section 3.7: do {...} while (...); skim. Section 3.8: for statement. Know this. Section 3.9: Design discussion. We did *not* go over the example of this chapter in detail. Section 3.10: Loops in applets, basically Chapter 4: only functions ("methods") will be on the exam. Section 4.2: Anatomy of a method, including parameters. Suggested end-of-chapter exercises: Chapter 2: Self-Review Questions (p 119): 2.10, 2.13, 2.16 Exercises (p 120): 2.4, 2.5, 2.8, 2.12, 2.16, 2.18 Chapter 3: Self-Review Questions (p 197): 3.3, 3.4, 3.6, 3.13, 3.15 Exercises (p 198): 3.4, 3.5, 3.6, 3.9, 3.13, 3.14, 3.18 Chapter 4: Exercises (p 262): 4.2, 4.3, 4.4, 4.5, 4.7 Example problems: These all involve writing part of a program; such problems tend to be hard. There will also be easier problems such as: format the following with reasonable indentation correct the syntax errors what does this program do? What is the output? 1. Write a loop to draw N circles in a horizontal row, each of diameter 50, and starting at x=0, y=100. The y coordinate never changes; the x coordinate is incremented by 50 each time. 2. Write a loop to add up the numbers from 1 to N. Put it inside a function that takes N as a parameter. 3. Write a function printMultiple that takes two parameters, an int n and a char ch, and prints n copies of that character: printMultiple('a', 4) should yield aaaa. 4. *Using* the function printMultiple above, write a loop to draw * *** ***** ******* (each row has two more *'s than the previous row.) 5. Write a function that reverses a string: public String reverse (String s) { } This one is hard, although we did do a class example about this. Hint: let n = s.length(). The letters of s are s.charAt(n-1) down to s.charAt(0). Append these (with +=) in turn to an initially empty string.