CPSC 170 Spring 2003
Program 1: Client Sales
Problem Description
Company XYZ has ambitious salespeople who are interested in organizing their
sales and keeping statistics about which clients they are selling the most
to. Each salesperson
keeps his or her sales information in files, one file for each
month.
Each line in a sales file contains
the information for a single sale -- the client's name and the dollar amount
of the sale. A salesperson might sell to
a single client many times in the same month, in
which case there will be many lines
for that client in the same file. Of course, the same client may
also appear in different files.
The salespeople have requested a program to read
the sales information from one or more files and
consolidate the sales for each client.
So if salesperson Joe had three sales to
client ABC, for amounts $50, $200, and $175, he really just wants to know
that he sold a total of $425 to ABC. The salespeople would also like the following
information:
- A list of clients with the total sales for each, from highest total
sales to lowest total sales.
- Which client had the greatest number of sales (not necessarily the
highest dollar amount).
Your job is to write a program to carry out these tasks as outlined below.
Program Structure
You will need to write two classes for this program, in addition to the driver.
Class ClientSales should hold three pieces of information -- the name of a
client, the number of sales to that client, and the total amount of sales to
that client. It should have the following public methods:
- ClientSales(String client, double sale) -- constructor; creates a new
ClientSales object with the given client and sale values.
- void addSale(double amt) -- adds the amount of the sale to the current
ClientSales object.
- String getClient() -- returns the name of the client.
- double getSales() -- returns the total sales to this client.
- int getNumSales() -- returns the number of sales to this client.
- String toString() -- returns the information for this client, neatly formatted.
Class SalesInfo should hold all of the sales information for a single
salesperson. It should use an array of ClientSales objects to store this information.
SalesInfo should have the following public methods:
- processFile(String filename) throws IOException -- takes
the name of a file with sales information and adds it to the
information already stored for the current salesperson.
- double totalSales() -- returns the total sales to all clients for this
salesperson
- ClientSales maxNumSales() -- returns the information for the client
with the highest number of sales.
- String toString() -- returns information for all of the clients ordered
by amount of sales (most to least)
client in table format.
You will need some private methods as well, including the following:
- void addSale(String client, double amount) -- adds the current sale to the
information for this salesperson.
- int findClient(String client) -- returns the index of the object
for the
given client in the sales array.
- void sortBySales() -- sorts the array from the client with
the highest sales to the client with the lowest sales.
You may wish to use other private methods as well.
Your driver should take the files to be processed on the command line.
It should create a SalesInfo object and repeatedly call the processFile method
for that object
to process the given files. It will then use the toString and maxNumSales
methods to print the remaining information. Note that the driver does not need to manipulate
any ClientSales objects directly.
Input
Your program should take the files to be processed on the command line, e.g.,
java TestSales salesFile1 salesFile1
There can be an arbitrary number (> 0) of input files
If no such files
are provided, the program should print a "usage" message and terminate.
Each input file will be in the following format:
client
saleAmt
client
saleAmt
client
saleAmt
...
end
You may assume that there are no spaces in the client names. The last line will
always be "end" (no quotes).
It is possible that a salesperson will not have any sales for the given month, in which case
the file will contain only "end". No salesperson will sell to more
than 25 different clients, but there may be more than 25 individual sales, that is,
more than 25 lines in any given input file or combination of files.
Output
Your output should contain all of the required information and be neatly formatted.
For example, consider the input files below:
Input File 1 Input File 2
--------------- -------------
SuperSteel ABCParts
12.15 10
ABCParts TiresLtd
123.50 100.75
SuperSteel end
50
SuperSteel
35.67
end
Output for these files might be as follows:
Client $ Sales # of Sales
-----------------------------------------
ABCParts $133.50 2
TiresLtd $100.75 1
SuperSteel $97.82 3
Total sales: $332.07
Highest # of sales: SuperSteel $97.82 3
What to Turn In
Turn in hardcopy of all of your classes. Tar your prog1 directory and e-mail it to me with
cpsc170 prog1 in the Subject line.