Computer Science 122


Assignment 3
Due: February 14, 2002

This time, read a list of checks into an array of objects.  Follow the example for a list with an array of objects.  First read the data for the checks into an array of checks.  Then display all the checks on the screen.  After that find the total amount of the checks and display that.  Finally, display all the checks with an amount greater than or equal to $50.00.  Note, do not have any dollar signs ($) or blank lines in your input file.  Make sure that there are no blank lines at the end of the file either.

You should have a main class that calls the methods in the class that reads in and displays the data.  The actual reading of the check data and display of the data should be in the Check class.  You also will need an accessor method, getAmount () in your Check class.  It only has to return the amount of the check.

Write separate methods for reading the data, displaying the data, finding the total of the check amounts and displaying checks with the amount over $50.00.  These should all be in the class that manages the list.  The Check class should have a method to read all the data except the first line (the date) and another method to display the data.  It will also need a constructor and the getAmount () method.  Note that this is used in statements such as

    if ( list [count].getAmount () >= 50)
        list [count].displayCheck ();
 
Finally in order to display the total amount of the checks with two decimal places, you may use the following method.  In order to use it, you will have to import java.text.*;.  Note that the parameter for this method is a double and it returns a String.  It can be used in an output statement such as

    System.out.println ("The total amount is " + decimals (total));

// Formats a double for string output with two decimal places.
public String decimals (double number)
{
     DecimalFormat decFor = new DecimalFormat ();
     decFor.setMaximumFractionDigits (2);
     decFor.setMinimumFractionDigits (2);
     return decFor.format (number);
} // method decimals

You may use your own data file or the following:
01/31/2002
101
Keyspan
35.66
02/04/2002
102
ConEdison
35.12
02/04/2002
103
Red Cross
75.00
02/05/2002
104
MasterCard
120.58
02/05/2002
105
Waldbaums
56.95
02/08/2002
106
Gap
136.98