We want to realize a program for managing the fund-raising activities of volunteers working in a no-profit organization. For each volunteer, the following information is stored:
Part 1.
Write a class Volunteer
that implements the following methods:
Volunteer(String name)
: constructor that creates an object
representing a volunteer whose name is name
, whose initial
bonus is 0, and whose initial amount of money is 0.
String getName()
: that returns the name of the volunteer;
double getBonus()
: that returns the bonus of the volunteer.
double getAmount()
: that returns the amount of money
collected by the volunteer;
void collect(double m)
: that increases the amount of money
collected by the volunteer by m
; if m
is greater
than or equal to 1000, then the bonus is increased by 1 (percent).
void spend(double m)
: that decreases the amount of money
collected by the volunteer by m
, if m
is smaller
or equal than the amount of money collected, and otherwise does nothing.
void useBonus()
: that increases the amount of money
collected by the volunteer by the percentage specified by the bonus, and
sets then the bonus to 0.
String toString()
: that returns a string with all the
information about the volunteer.
Example program:
TestVolunteer.Java
Part 2.
Write a class UseVolunteer
, client of Volunteer
, that
contains the following public static method:
static double totalAmount(Volunteer v1, Volunteer v2)
:
that, given two volunteers v1
and v2
, calculates
and returns the sum of the amount of money raised by the two volunteers,
considering also the bonuses.
v1
and v2
is applied to the sum of
the money raised by v1
and v2
.
Example program:
TestUseVolunteer.java
Solutions:
Volunteer.java
,
UseVolunteer.java