At this point, we can do the
following:
- Write a single main method containing a
series of computations
- These computations can be performed over
variables of type int, boolean, char, and
double
- Assign String variables and perform
some operations over these values
- Perform simple text output to the console,
using print and println.
But we have the following problems:
- All computations are defined in a single main
method. This design is hard to maintain and extend, and makes it
impossible to reuse just parts of the main method.
Goal: we need some way to decompose computations [see
Nov-03]
- If we want to store a set of values, say the
grades for a student, we would have to "hard code" the variables as
exam1, exam2, and exam3. This approach is not
extensible and very hard to keep up-to-date, since the number of
exams is quite likely different across different course offerings.
Goal: We need some way to group multiple values (of the same
type) together [see Oct-31]
- To store related information, we would use
multiple variables. Thus, a point in space could be represented by
variables x1 and y1, while another point would be
stored by x2 and y2. This is inefficient, and forces
the programmer to remember too many things.
Goal: We need some way to group heterogeneous, but related,
values together
|