CPSC-115 Fall 2008
Lab 5
October 8, 2008
Professor Heidi Ellis

Be sure that you hand in the printouts of your work before leaving!!!

Objective:

For this lab, you must write a program to be used in a library domain to calculate the overdue charges for a customer. When a customer checks an item out of a library, that item has a due date which indicates when the item must be returned to the library. If the item is not returned to the library by the due date, then charges are applied for each day that the item is not returned.

Pre-lab: The prelab for Lab 6 is to create a flowchart algorithm for the program. Hand in the flowchart at the beginning of class.

Pair Programming: You may complete the lab either in pairs or individually. Please put the names of all team members in the comments in the class header.

In this lab, you must write a program to support the calculation of overdue charges for a library. The program reads input from a file that contains a customer name and a series of overdue items. The information for the items includes the type of the item (book, CD, or DVD), the title of the item, the replacement cost if the item must be replaced, and the number of days the item is overdue. The per-day overdue charges for the various types of items are as follows:

Your program must calculate the overall replacement charge for all items that are overdue for a customer and the total overdue charges for all items checked out by a customer. The customer name, replacement cost and overdue charge are printed to an output file.

The input file contains information for multiple customers. A sample input file might look like:
Jane Doe
CD
Counting Crows, Best of
15.99
5
DVD
Harry Potter, V2
29.99
10
NEXT
Roy Reader
Book
Gone
24.95
34
Book
One Soul Lost
34.87
26
Book
Forever Grateful
34.89
25
NEXT
Sun Songster
CD
J.S. Bach Greatest Hits
12.99
10
CD
Nirvana, In Heaven
31.88
23
In the example above, the first customer's name is Jane Doe. Jane has two overdue items:
  1. The Best of Counting Crows CD with a replacement cost of $15.99 that is five days overdue.
  2. Harry Potter, V2 DVD with a replacement cost of $29.99 which is 10 days overdue.
Note the use of the NEXT delimiter. This is a string inserted into the input file to identify the end of one customer's information and the beginning of the next.

A sample output file that holds the output for the input file above might look like:
***** Customer Charges *****

Customer: Jane Doe has 2 items overdue
The total overdue charge is: $12.5
with a total replacement cost of: $45.98

Customer: Roy Reader has 3 items overdue
The total overdue charge is: $4.25
with a total replacement cost of: $94.71

Customer: Sun Songster has 2 items overdue
The total overdue charge is: $16.5
with a total replacement cost of: $44.87
You will need to use two loops where one loop is nested within another in order to complete this program. The outer loop should iterate until there is no more customer data. The inner loop is used to process the items for an individual customer.

Test your code carefully to make sure that it operates correctly under a variety of test cases. Your code should have good programming style and follow all Java conventions. Don't forget to use constants where appropriate.

You're done!! Don't forget to log out and hand in your printouts to the professor before you leave!!