Exercise 11/28/2006
|
Deli Cheeses
|
Due: Friday, December 8
5pm
|
Relevant Reading:
- Readings on Arrays in Head First Java:
- Pgs 17-19
- Chapter 3, starting at page 59
- Pg 83
Assignment: (worth 10 exercise points)
Get the ex11-28.zip
file. Use the
files
in this folder as your basis for this assignment.
The program as given reads in a data file containing information on cheeses. The format is:
A series of info on cheeses, for each cheese:
First line: name of the cheese
Second line: number of pounds in stock
Third line: price per pound of the cheese
Sample data files are deli1.txt, deli2.txt, deli3.txt, and deli4.txt. (Although
your program should work on any files that conform to the specifications.) Other
Note:
-
Opening the data files in Notepad may have it look odd. Use Wordpad or another editor instead.
The program already has code that creates the Inventory and displays
it. You are welcome to go look at the file
CheeseFileHandler.java, because it may give you some interesting ideas
and insights, but it is not required. You may also wish to look at the Files sample programs in the samples directory.
Add
the following to the program. You may modify any of
the files that you wish (but I recommend AGAINST modifiying
CheeseFileHandler.java or Cheese.java. If you DO modify them, you
should put in the comments that you modified them and also an
explanation as to WHY you modified it.
a) report how many pounds of cheese is in stock (add up all of the pounds)
b) report the name of the most expensive cheese. (If there are
no cheeses in the list, your program should say "no cheeses" and NOT crash.)
c) add 10 cents to the price of every cheese. The new
list should then be displayed on the screen. (Check to see that
all prices have been modified.) Further, check that the file has
the new prices in the end. You may notice numbers that are long like:
3.1499999999. More than two decimal places is okay as long
as they are "correct" when rounded. Extra Credit: Get the decimals to always be two after the decimal point.
d)
New Shipments.
- Let the user type in the name of a cheese and the amount
in stock. If that cheese is already in the list, add the new
amount to the old amount. If the cheese it not already in the
list, then ask them for the price, and add the new cheese to the list.
- Put
this in a loop so that they can enter multiple shipments. The
user should be able to enter as many shipments as they wish.
- Be sure the file indicates the changes when the program is done.
e) When the above has finished, ask the user how they would like
the inventory sorted - either by price or number of pounds in
stock. The program should then sort the info in the
file. Should the file be in increasing order or
decreasing order? You should ask the user which they want.
Extra Credit:
- Use the JFileChooser class to bring up a better dialog box that lets the user hunt for the file they want.
Handin:
-
Be sure to read the general handin instructions on the exercises page.
-
Rename the folder containing all of the files to be
"lastname-firstname-100SectionLetter-deli". For example, if I were in Section Z, I would rename my folder to
be: "McElfresh-Scott-100Z-deli"
(without the quotes).
- Create a zip file of this folder, with the same name as the folder (except
with the .zip ending this time). Instructions for zipping can be found in
the system and software handouts linked on the main course page.
- Submit this file via the electronic
handin. If you have problems, contact me.
|