Programming and Problem Solving with Java

(やまだぃちぅ) #1
1.1 Overview of Object-Oriented Programming | 5

erations serves to represent objects. The objects we represent can be either phys-
ical objects from the real world, such as products in an inventory, or abstract
objects, such as mathematical constructs. Our computer representations of ob-
jects are then programmed to interact as necessary to solve a problem.Datais
information in a form that the computer can use—for example, numbers and
letters.Informationis any knowledge that can be communicated, including ab-
stract ideas and concepts such as “the Earth is round.”
Data come in many different forms: letters, words, integer numbers, real
numbers, dates, times, coordinates on a map, and so on. In the absence of oper-
ations that manipulate the data, however, these forms are essentially meaning-
less. For example, the number 7.5 has no meaning out of context. In the context
of an operation that computes it from a measurement of a person’s head, how-
ever, it becomes a hat size. The combination of data with related operations, in
the form of an object, makes it possible to represent information in the computer.
Virtually any kind of information can be represented as an object.
Just as a concert program lists the pieces to be performed in the order that the
players will perform them, a computer program lists the objects needed to solve a
problem and orchestrates their interactions. From now on, when we use the words
programmingandprogram, we meancomputer programmingandcomputer program.
The computer allows us to perform tasks more efficiently, quickly, and ac-
curately than we could by hand—if we could do them by hand at all. For this powerful ma-
chine to be a useful tool, however, it must first be programmed. That is, we must specify
what we want done and how. We do so through programming.


How Do We Write a Program?


A computer is not intelligent. It cannot
analyze a problem and come up with a
solution. A human (the programmer)
must analyze the problem, develop the
objects and instructions for solving the
problem, and then have the computer
carry out the instructions. What’s the
advantage of using a computer if it can’t
solve problems? Once we have written a
solution for the computer, the computer
can repeat the solution very quickly and
consistently, again and again. In this
way, the computer frees people from
repetitive and boring tasks.
To write a program for a computer
to follow, we must go through a two-
phase process: problem solvingand im-
plementation(see Figure 1.1).


PROBLEM-SOLVING PHASE IMPLEMENTATION PHASE

Concrete solution
(program)

Ver ify Test

General solution
(algorithm)

Analysis
and specification

MAINTENANCE PHASE

Figure 1.1 Programming Process

Data Information in a form
that a computer can use
Information Any knowledge
that can be communicated
Object A collection of data
values and associated
operations
Computer programming The
process of specifying objects
and the ways in which those
objects interact to solve a prob-
lem
Computer program
Instructions defining a set of
objects and orchestrating their
interactions to solve a problem
Free download pdf