Programming and Problem Solving with Java

(やまだぃちぅ) #1

(^6) | Introduction to Object-Oriented Programming
(^2) Java supports two types of programs, applications and applets. An appletis a restricted form of applica-
tion that can be executed by a Web browser. We do not use applets in most of this book, but Chapter 14
explains how applications and applets differ and shows how to convert an application into an applet.
Problem-Solving Phase
1.Analysis and specification. Understand (define) the problem and identify what the
solution must do.
2.General solution (algorithm). Specify the objects and their interactions that solve
the problem.
3.Verify. Follow the steps exactly to see if the solution really does solve the problem.
Implementation Phase
1.Concrete solution (program). Translate the object specifications and algorithms (the
general solution) into a programming language.
2.Test. Have the computer carry out the program and then check the results. If you
find errors, analyze the program and the general solution to determine the
source of the errors, and then make corrections.
Once a program has been written, it enters a third phase: maintenance.
Maintenance Phase
1.Use. Use the program.
2.Maintain. Modify the program to meet changing requirements or to correct any
errors that show up in using it.
The programmer begins the programming process by analyzing the problem,
identifying the objects that collaborate to solve the problem, and developing a
specification for each kind of object, called a class. The objects work together to cre-
ate an application that solves the original problem. Understanding and analyzing
a problem take up much more time than Figure 1.1 implies. These tasks form the
heart of the programming process.
A program is an algorithmthat is written for a computer. When we define
classes of objects and orchestrate their interactions to solve a problem, we are
writing an algorithm. We generally refer to Java programs as applications.^2
More generally, an algorithm is a verbal or written description of a logical set
of actions involving objects. We use algorithms every day. Recipes, knitting in-
structions, and driving directions are all examples of algorithms that are not programs.
When you start your car, for example, you follow a step-by-step set of actions involving
various objects. The algorithm might look something like this:
Objects: Key, Transmission, Gas Pedal, Engine, Phone
1.Insert the key.
2.Make sure the transmission is in Park (or Neutral).
Class A description of the rep-
resentation of a specific kind of
object, in terms of data and op-
erational behaviors
Algorithm Instructions for
solving a problem in a finite
amount of time using a finite
amount of data

Free download pdf