CS 051 Fall 2011

Lecture 3

Accessor and Mutator Methods

Mutator methods: Accessor methods: Class Example: Crosshairs

Numeric types and Conditionals

Numbers are different from graphical objects.
However, you can create instance variables that refer to a number, and you can perform
operations on numbers and instance variables that reference numbers.

You can also combine numbers with strings in the output.

Class Examples: ClickCounter and MouseMeter

Constant Names

Constants in programs should be given names so that the program is more easily
readable by humans. Constant names should be meaningful, and are traditionally given in
all capital letters, with underscores for the spaces between words.

For example: MAX_SCORE

In java:

Conditionals

We use the "if-statement" in Java to execute selected statements only under certain conditions.

Class Example: Basketball

The "if" statement is, itself, a statement. It can be icluded in those statements to be
conditionally executed! Class Example: BetterBasketball

Simple conditions in "if" statements can be combined using logical operators for and (&&),
or (||), and not (!).

Color

You can use predefined colors from the java.awt.Color class such as:
        Color.RED

You can also define your own colors by creating a new color object such as:
        new Color(200, 0, 0)

which produces a light shade of purple.