## Lab Exam 23/11/2005 (18:00-20:00)

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:

• name (a string),
• bonus (in percent) granted by the Province (a double),
• amount of money that the volunteer has collected (a double),

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.
• If both volunteers have a positive bonus, the maximum bonus among those of `v1` and `v2` is applied to the sum of the money raised by `v1` and `v2`.
• If only one of the two volunteers has a positive bonus (and the other one has bonus 0), then the positive bonus is applied only to the money of that volunteer.
• If both volunteers have a bonus of 0, then no bonus is applied.

Example program: `TestUseVolunteer.java`