Computer Science
15-111 (Sections A & B), Spring 2007
Class Notes: 29-Jan-2007
Logistics
Topic Outline:
1. On Style: “Magic Numbers”
a. A simple rule: no literals in expressions besides -2, -1, 0,
1, 2.
b. Bad: drawCircle(pixels,250,50,50,…)
c. Better:
drawCircle(pixels,width-radius,radius,radius,..)
d. Reads better, fewer bugs, more
easily modified, etc, etc, etc…
2. Enumeration Operations (Section 6.4)
a. equals(), name(), ordinal(),
values()
b.
FadeType
type1, type2;
if (type1.equals(type2)) { … } // not equals(type1,type2)
c.
for
(FadeType fadeType : FadeType.values()) {
System.out.printf("%d:
%s\n”,fadeType.ordinal(),
fadeType.name());
}
Outputs:
0: HORIZONTAL_FADE
1: VERTICAL_FADE
2: RADIAL_FADE
3. Classes: a 10-minute tour of Sections 6.6 to 6.10
a. Create a new class (Counter)
b. Adding instance variables (value)
c. Adding instance methods (get(),
click(), reset())
d. Making instance variables private
e. Counting instances
i.
Adding
a constructor (and losing the default constructor!)
ii.
Adding
a static (class) variable -- howMany
iii.
Adding
a static (class) method -- howMany()
4. Pixel image demo part 2: Zooms and/or Thumbnails of jpegs!
5. 2d Arrays: Either matrix operations or Gaussian
Elimination (depending on time)