Dr. Roger Webster
Goals
- to use files to get information
- to use arrays to
hold and access information
- to write methods and use parameters
effectively
Overview
For this assignment, you will write a Java program to simulate
a grocery store checkout system. Information about store items: item code (sku
bar code), name,
cost per unit, and whether the item is sold by pounds or quantity will be
stored in a file. Standard input will contain the name of that file followed by
lines representing items to be purchased. Your program will be able to lookup items and total cost.
This program will make use of your knowledge of: Objects, Arrays, Methods, File I/O,
GUI programming, Mouse programming, Sorting, and Binary Searching.
Checkout Description
You are to open the file and read the contents to obtain the
information on items for sale. The file will contain one line per item. The line
will contain four values. The values are 1: item number (an integer), 2: item
name (a string), 3: item price (a double), and 4: item type (a string, either
pounds or each). You may assume the item information file is
properly formatted.
There will be no more than 1000 items in the file. If more are encountered, print an error message and terminate the program..
The item number is a SKU Stock Keeping Unit or the bar code and can be any positive integer. Hint: Do NOT use them as an index into an array since they have a very large range. The item name is a string of non-space characters. The item price is a positive real number. The item type is a string. It is either pounds, meaning the item is sold by the pound, or it is each, meaning the item is sold by units. Note that the lines in the file are not sorted in any way.
You should read the four values for each item into an object and store the
objects into an array to hold the
item data in memory. To read the
item data file you will need to open the file. You should have sample code
pieces to read data in from a text file.
After the item file name (you can download the groceryfile.dat on my web site) the standard input will contain purchase information. Each line will contain an item number and a quantity or weight as appropriate for the item. You should write out a line of information for the purchase after reading each input line. To compute the appropriate output line, you will need to look up the item number in the item number array and consult the other arrays with the same index to obtain information about the item. If the item number is not in your array, print a message and skip the item.
After all input has been read in, sort the array by bar code (SKU) using the selection sort you have already programmed.. Then you can use a binary search method to find or not find items in the inventory. Use a GUI to ask the user for the SKU and then return using a GUI all the info about the object.
Sample File (see rwwfile.dat)
1200 2litercoke 1.19 each 15 greenbeans 0.69 pounds 216 Kellogscereal 3.99 each 75 2literPepsi 1.09 each 100 V8Juice 2.99 each 87 bananas 0.99 pounds 1234 peaches 1.05 pounds 19 OJcans 0.98 each 91200 2literOrange 1.19 each 915 Cutgreenbeans 2.69 pounds 9216 Postcereal 4.99 each 975 2literSprite 1.49 each 9100 PineappleJuice 1.99 each 987 Tomatoes 0.99 pounds 91234 GeorgiaPeaches 1.55 pounds 919 BakedBeans 0.98 each 81200 2literDrPepper 1.19 each 815 Waxgreenbeans 2.69 pounds 8216 FruitLoopscereal 4.99 each 875 2literRootBeer 1.49 each 8100 CranberryJuice 1.99 each 887 GreenPeppers 0.99 pounds 819 hotdogs8pack 2.98 each etc.