Class Donations

java.lang.Object
  |
  +--Donations

public class Donations
extends java.lang.Object

This class maintains a list of donors by their ID number (any integer). For each donor, it keeps track of the number of donations and the total amount of the donations. The class provides methods for updating the list, looking up donation information by the ID number and sorting donor IDs by number or amount.

Written September 2002 by Craig Miller


Constructor Summary
Donations()
          Constructs an empty donor list.
 
Method Summary
 void addDonation(int id, java.lang.String amount)
          This method adds the amount of a donation to the current total for the specified donor (by ID number).
 java.lang.String getDonationTotal(int id)
           
 int[] getDonorIDsByNumber()
           
 int[] getDonorIDsByTotal()
           
 int getNumberOfDonations(int id)
           
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Donations

public Donations()
Constructs an empty donor list.

Method Detail

addDonation

public void addDonation(int id,
                        java.lang.String amount)
This method adds the amount of a donation to the current total for the specified donor (by ID number). If this is the first donation, a new entry is added to the list.

Parameters:
id - the identification number of the donor
amount - the amount of the new donation specified as a formatted string in dollars and cents (e.g. "10.00" or "5.50")

getDonorIDsByNumber

public int[] getDonorIDsByNumber()
Returns:
the array of donor IDs sorted by the number of donations, in ascending order

getDonorIDsByTotal

public int[] getDonorIDsByTotal()
Returns:
the array of donor IDs sorted by the total amount of donations, in ascending order

getNumberOfDonations

public int getNumberOfDonations(int id)
Parameters:
id - the identification number of the donor
Returns:
the number of donations by the specified donor

getDonationTotal

public java.lang.String getDonationTotal(int id)
Parameters:
id - the identification number of the donor
Returns:
the total amount of donations by the specified donor

main

public static void main(java.lang.String[] args)