Java Reference
In-Depth Information
different project, or fired), so other programmers
must
be able to read and under-
stand the program.
Some programming habits concern syntactical measures, like indenting pro-
gram parts properly and using certain conventions for names of variables, meth-
ods, and classes. Other habits concern describing code in comments so that the
reader can understand how a program is designed.
It is important to practice good programming habits
all the time
. This will
possibly be an uncomfortable part of learning to program, but it is the part that
will help you the most in the long run.
From time to time, you will find short discussions on programming conven-
tions and style in this text. These are summarized in Chap. 13, and we suggest
that you skim that chapter now to get a sense of what it contains, and then return
to it at regular intervals to make sure that you understand and are following our
style conventions.
Exercises for Chapter 1
E1.
Suppose d is of type
double
. For what values of
x
do the following expres-
sions give the same result, and for what values do they give different results?
(
int
) d
(
int
) Math.round(d)
E2.
Do the same as exercise 1 for these two expressions:
(
int
) d
(
int
) Math.ceil(d)
(
int
) Math.floor(d)
E3.
Write and test a class
DoubleFrame
that customizes
JFrame
to have a method
with this specification:
/**
Double the width and height of this window
*/
public void
doubleDimensions()
E4.
Write and test a class
SwitchFrame
that customizes
JFrame
to have a method
with this specification:
/**
Switch the width and height of this window
*/
public void
switchDimensions()
E5.
Write and test a class
DateFrame
that customizes
JFrame
to have a method
with the specification given below. Class
Date
has a special way of encoding the
month and year; use whatever that class gives you for a month and year.
Search WWH ::
Custom Search