Cryptography Reference
In-Depth Information
if
x
is negative, change the sign of both
q
and
r
, since
x
=
yq
+
r
iff
x
=
(
yq
+
r
)
iff
x
=
y
(
q
)
r
,
and if both
x
and
y
are negative, change the sign of
r
, since
x
=
yq
+
r
iff
x
=
(
y
(
q
) +
r
)
.
With this in mind, writing a division method should be a snap.
Naturally, the arithmetic methods must be tested. No programmer ever designs a class
without writing a multitude of programs to wring all the bugs out of it. I ' ve written a sim-
ple applet to do this. I ask the user to enter an Int in a text field, and then they click an oper-
ation, either + , , or * . They then enter another Int and press the = button. This is
the beginning of a calculator; you will be asked to produce a better one in the exercises. Some
screen shots follow, and the applet can be found on the topic ' s website under the class name
TestIntArithmeticMethodsApplet. (See Figure 2.4a - c.)
x
=
yq r
(a)
FIGURE 2.4
(b)
Search WWH ::




Custom Search