Java Reference
In-Depth Information
Exercise P4.9. Implement a class
SodaCan
whose constructor receives
the height and diameter of the soda can. Supply methods
getVolume
and
getSurfaceArea
. Supply a
SodaCanTester
class that tests your
class.
Exercise P4.10. Implement a class
Balloon
that models a spherical
balloon that is being filled with air. The constructor constructs an empty
balloon. Supply these methods:
ȗ
void addAir(double amount)
adds the given amount of
air
ȗ
double getVolume()
gets the current volume
ȗ
double getSurfaceArea()
gets the current surface area
ȗ
double getRadius()
gets the current radius
Supply a
BalloonTester
class that constructs a balloon, adds 100Ю
cm
3
of air, tests the three accessor methods, adds another 100Юcm
3
of air,
and tests the accessor methods again.
Exercise P4.11. Giving change. Enhance the
CashRegister
class so
that it directs a cashier how to give change. The cash register computes the
amount to be returned to the customer, in pennies.
Add the following methods to the
CashRegister
class:
ȗ
int giveDollars()
ȗ
int giveQuarters()
ȗ
int giveDimes()
ȗ
int giveNickels()
ȗ
int givePennies()