Java Reference
In-Depth Information
coordinates and produces a nicely formatted table of the triangle
properties.
This is a good team project for two students. Both students should agree
on the
Triangle
interface. One student implements the
Triangle
class, the other simultaneously implements the user interaction and
formatting.
Project 4.2 The
CashRegister
class has an unfortunate limitation: It
is closely tied to the coin system in the United States and Canada.
Research the system used in most of Europe. Your goal is to produce a
cash register that works with euros and cents. Rather than designing
another limited
CashRegister
implementation for the European
market, you should design a separate
Coin
class and a cash register that
can work with coins of all types.
ANSWERS TO SELF-CHECK QUESTIONS
1.
int
and
double
.
2. When the fractional part of
x
is ʏ0.5.
3. By using a cast:
(int) Math.round(x)
.
4. The first definition is used inside a method, the second inside a class.
5.
(1) You should use a named constant, not the Ȓmagic numberȓ 3.14.
(2) 3.14 is not an accurate representation of ƚ.
6. The statement adds the
amount
value to the
balance
variable.
7. One less than it was before.
8. 17 and 29.
9. Only
s3
is divided by 3. To get the correct result, use parentheses.
Moreover, if
s1
,
s2
, and
s3
are integers, you must divide by
3.0
to avoid
integer division: