
Computer Science 3310
Program 1
Your assignment is to write, run, and test a program to simulate the operation of a grocery store checkout system. The program
should operate as follows:
1. Read from an input data file the inventory information. The data file should be named inventory.dat. T here is one input
line per product, and these lines have the following format:
<product number> <description> <price> <tax>
where <product number> is a five-digit positive integer (you may assume the leftmost digit is not a zero), <description> is
a string of at most 12 characters with no embedded blanks, <price> is a real number, and <tax> is a character (‘F’ if the
product is a food item; ‘N’ if it is a non-food item). The tax rate is 7% for non-food items and 2% for food items. You
may assume the inventory has no more than 100 items (a small store!).
2. Read from standard input the customer purchases and output the cash register receipt for the customer to standard output.
Each input line should have the following format.
<product number> <times>
where <product number> is as described above, and <times> is an integer in the range 1 to 100 indicating the quantity
purchased. A zero input for <product number> and <times> indicates the end of the customer’s purchases. There may be
multiple customers in one file. Use the end-of-file marker to detect the end of the data. For output the receipt should be
nicely formatted with the product description (not the product number), number of items, item price, and total price for
each product printed on a single line. At the end of each customer’s purchases, the subtotal for all items, amount of tax,
and total bill should be printed, clearly labeled. Produce this output as you are reading the purchases. A sample is shown
at the end of the specification.
3. Error Checking: The following input errors are possible and should be handled by your program.
• <product number> not in the inventory file. Write an error message on the receipt, ignore that product number, and
continue with the next item.
• Duplicate <product number> in the inventory file. Write an error message to the screen and skip the second entry.
Note that the duplicate may not come immediately after the original.
• <times> not in the specified range. Write an error message to the receipt, ignore that line, and continue with the next
item.
PROGRAM DETAILS
• Program Structure:
Your source code should be developed in two files: GroceryItem.java and GrocerySim.java. GroceryItem.java will
contain the class definition for a grocery item according to the requirements specified below. GrocerySim.java will
be the class definition that includes the actual main program for running the simulation.
• Data Structure:
Each inventory item should be an object of the GroceryItem class. Define a separate instance variable of the
appropriate type for the four items of information about each inventory item. Instance variables should be
maintained as private data. Required methods for the class are the following.
An accessor method for each instance variable.
A readItem method that will take as an input parameter a Scanner object that represents the input file being
read. This method should then read in all the information for one inventory item and leave the position of the
Scanner object at the beginning of the next input line.
A static method itemSearch that takes three input parameters: (1) an array of GroceryItem objects that represent
the entire inventory; (2) an integer specifying how many elements of the array from (1) are actually being used;
and (3) an integer representing a product item. The method should search the array of items looking for the