IT 484 Assignment #1

Exercise #6.1 p222 (this requires an array, since you need to go through the
numbers again after you have calculated the average); Exercise #6.5 p222 ...
Then, your program will output to the screen the summary of revenue for the
regions, and also display the units sold and total revenue each product, along
with the ...

Part of the document


CIS 331 Assignment #4
Arrays, Strings, and Stream I/O
Product Sales Summary

Due via blackboard by midnight Saturday 2/27/10


CARRY-OVER FROM ASSN3

Include these exercises from the book, unless you did them with assn3.
Although they were initially intended for assn3, the snow days prevented us
from covering the necessary materials in

1. Exercise #6.1 p222 (this requires an array, since you need to go
through the numbers again after you have calculated the average)
2. Exercise #6.5 p222



THE MAIN ASSIGNMENT

For this assignment, you will write a program that reads product sales data
from a text file, and then calculates the total revenue earned for each
sales region and the total units sold and total amount of revenue earned
for each product. The text file will contain one line of text for each
product. Each line consists of the following data (delimited by spaces or
tabs):

1) product name
2) product price
3) units sold in North
4) units sold in South
5) units sold in East
6) units sold in West

For example, consider this text file:

[pic]

The price of DiskDrives is $325.50, and 100 units were sold in the north,
200 in the south, 300 in the east, and 250 in the west. You can see similar
data for Computers, Printers, WirelessCards, and NetworkServers.

Your program should prompt the user (using standard input stream...no GUI
please) for the file path:

[pic]




Then, your program will output to the screen the summary of revenue for the
regions, and also display the units sold and total revenue each product,
along with the average revenue and products generating higher than the
average. For the above data, the output will look like this:

[pic]


Note that the program first asks the user to enter the input file. Then it
outputs the total revenue for each region and a grand total. (From the
input data, you should be able to verify the validity of these result by
performing a manual calculation.) After displaying the region summaries,
the product-specify summaries are calculated. As you can see, a total of
100 computers were sold (25 in each region), and at $595 per unit, this
came to a total of $59500.

Note also the currency format of the output, with a dollar sign preceding
the revenue quantity and comma separating the thousands place. This can be
done using: the NumberFormat class found in the java.text package. See page
1031 of your textbook for assistance in doing this. I expect your output to
display proper currency format.

Your program must be flexible enough to handle a variety of input files.
There may be as many as 100 products in the file. But in all cases, a
single line of the text file will be structured as described above.


Program Data Representation

To make this work, you will need to create five arrays.

One array will contain the product names. A second array will contain the
total units for each product. A third will contain total revenue for each
product. These three are parallel arrays. This means that the same index in
each array pertains to the same entity. For example, for the above data,
the arrays for product names, units, and revenues will look like this at
the end of the program execution:


Names Units Revenue

|Computers | |100 | |59500 |
|DiskDrives | |850 | |276675 |
|Printers | |400 | |39980 |
|WirelessCar| |130 | |16315 |
|ds | | | | |
|NetworkServ| |130 | |130110.5 |
|ers | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |



These arrays must be large enough to handle an unknown number of products.
As stated above, there can be as many as 100 products in the file. But
there may also be less than 100. Therefore, although these arrays must be
large enough for the maximum amount, many of the elements of the arrays
will be empty. So, you should also have a variable to keep track of how
many products are actually read from the file. This total products variable
will also be used to keep track of the next available element in the three
arrays, and can be used to index into these arrays. For example, the total
products variable starts at 0, which means that you will index into element
0 of these arrays. For each product that you read from the file, you can
increment the total products variable. Thus, after you have processed the
first product, the total products variable will be 1, so you will index
into element #1 of the arrays. Thus, the total products variable serves two
purposes: keeping a running count of the products and indexing into these
three arrays.

The third and fourth arrays will contain the names of the regions and the
corresponding total revenue for each region. These are also parallel
arrays, but their size is much smaller. You only need enough elements for
the four different geographical regions.

You will also need other variables for keeping track of totals, inputting
data from the file, etc.



Program Logic

The logic of the program works something like this:

1) Prompt the user for the name of the file (note: this should be done
using standard input stream, not any GUI)
2) Read the response from the user.
3) Open the input file specified by the user (via the Scanner method
described in class)
4) Loop as long as there is more data to read:
a. Read the product name as a string, and place it into the product
name array
b. Read the price as a double, and place it into a variable to use
in the revenue calculation
c. Read the remaining integers from the file (sales for each
region). Use these to:
i. accumulate the total units for the product
ii. add the units times price to the correct element of the
region revenue array
d. place the total units into the units array, and place the units
time revenue into the revenue array for the product
e. add one to the count of total products. You can use total
product count to index into the names, units, and product
revenue arrays.
5) At this point you have accumulated all the data into the arrays. Now
it is simply a matter of displaying the results, and accumulating
grand totals. Each of these will be done in a loop.
6) Finally, calculate and display the average revenue for the products,
and identify the products that generate higher than the average


CAUTION

Conceptually, this is not a difficult problem, and doesn't take that much
coding to accomplish. My solution contains a total of approximately 60
lines of code in the main method. The problem of reading from the console
input, reading text files, and array processing is simply what you learn
from the class notes and code examples. You can use the code from these
examples to help you.

However, translating this from concept to result will be a challenging
task. You do NOT want to put this off to the last minute. There is no doubt
that you will encounter obstacles along the way.

Use the debugger to help identify problems and bugs. Also, make sure to use
me as a resource. I will give guidance where appropriate. But most
importantly, get an early start and work diligently and consistently
through the whole week.

PROGRAM STYLE

In addition to correct functionality of the program, I expect you to adhere
to sound programming style.
Use descriptive variable names. Be sure to use proper indentation in your
code and supply enough comments to make it clear what the program is doing.


At the top of your program listing, you need to include comments with:

1) your name and peoplesoft number
2) the course and section
3) the assignment number
4) a statement assuring me that this work was done in accordance to the
JMU Honor Code.






DELIVERABLES


For this program, I will want the following (all zipped together):

1) The .java file(s)
2) A screen image (captured using Alt+PrtScrn and pasted into a Word
document) showing the contents of memory at a particular "interesting"
breakpoint during the execution of your Product Sales Summary program
(use the debugger). This image should show an array expanded so that I
can see the contents of individual elements of the array.
3) A brief (1-2 sentence) description of what the debugger is showing you
at the time of the breakpoint



-----------------------
User input