Java Reference
In-Depth Information
΢΢T Exercise R6.16 Explain in detail how to inspect the information stored in
a Rectangle object in your debugger.
΢΢T Exercise R6.17 Explain in detail how to use your debugger to inspect the
balance stored in a BankAccount object.
΢΢T Exercise R6.18 Explain the divide-and-conquer strategy to get close to a
bug in a debugger.
Additional review exercises are available in Wiley PLUS.
PROGRAMMING EXERCISES
΢ Exercise P6.1 Currency conversion. Write a program
CurrencyConverter that asks the user to enter today's exchange rate
between U.S. dollars and the euro. Then the program reads U.S. dollar
values and converts each to euro values. Stop when the user enters Q .
΢΢΢ Exercise P6.2 Projectile flight. Suppose a cannonball is propelled
vertically into the air with a starting velocity v 0 . Any calculus book will
tell us that the position of the ball after t seconds is s(t) = ɨ0.5 – g – t 2 +
v 0 – t, where g 9.81Юm/sec 2 is the gravitational force of the earth. No
calculus book ever mentions why someone would want to carry out such
an obviously dangerous experiment, so we will do it in the safety of the
computer.
In fact, we will confirm the theorem from calculus by a simulation. In
our simulation, we will consider how the ball moves in very short time
intervals Ŷt. In a shor t time interval the velocity v is nearly constant, and
we can compute the distance the ball moves as Ŷ s = v – Ŷt. In our
program, we will simply set
278
279
double deltaT = 0.01;
and update the position by
s = s + v * deltaT;
Search WWH ::




Custom Search