Question
This question involves the implementation of a Fundraiser class. A Fundraiser object is created with a parameter representing a target amount of money to be
This question involves the implementation of a Fundraiser class. A Fundraiser object is created with a parameter representing a target amount of money to be raised. The Fundraiser class supports adding donations, determining an average donation amount, and reporting the amount still to be raised to meet a target.
The Fundraiser class provides a constructor and the following methods.
- addDonation adds a donation of the amount specified by the parameter (double) to the fundraiser.
- average donation returns the average amount donated, found by dividing the amount donated by the number of donations as a double. This should return 0.0 when no donations have been made.
- distanceToTarget returns the amount of money still to be raised to meet the target amount as a double. This is 0.0 once the amount raised is equal to or above the target amount.
The following table contains a sample code execution sequence and the corresponding results.
Write the complete Fundraiser class including the constructor and any required instance variables and methods. Your implementations must meet all specifications and conform to the example.
Statements and Expressions Value Returned (blank if no value) Comments Target amount for this fundraiser is $5000 0.0 No donations have been made so far. No money has been raised so far. Donation total now stands at $750 750.0 750.0/1 = 750.0 4250.0 5000.0 - 750.0 = 4250.0 Donation total now stands at $1875 Fundraiser f = new Fundraiser(5000.00); f.averageDonation(); f.distance To Target(); f.addDonation(750.00); f.averageDonation(); f.distance To Target(); f.addDonation(1125.00); f.addDonation(400.00); f.addDonation(1620.00); f.averageDonation(); f.distance To Target(); f.addDonation(124.75); f.addDonation(1030.60); f.averageDonation(); f.distance To Target(); Donation total now stands at $2275 Donation total now stands at $3895 973.75 3895.0/4 = 973.75 1105.0 5000.0-3895.0 = 1105.0 Donation total now stands at $4019.75 Donation total now stands at $5050.35 841.725 5050.35/6 = 841.725 0.0 Target amount has already been raised
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started