ITEC 120 Back to Assignment index page
   
Assignment 4 - Shopping
Due Mon, April 24, midnight. Submit your program to the RU09 folder in your directory on neelix.

Description:  You'll design and write a program to read in grocery items from a file, then discount certain items.

You'll implement an array of objects (grocery store items, using the class you wrote for program 3) to solve this problem.

Write a program to read a file called "shop.txt". This file contains a list of items a customer is buying, one item per line. Each line contains an item number, followed by a slash "/", an item name, followed by a slash, and a price. If the item is sold by weight, there will be another slash followed by the weight. Create an array of Items and store each of these items in it. Keep in mind that I will run your program with a file of unknown length, so your array must be expandable. After all items are read in, Print out a list of the items and the total price of all the items in the array. (A static variable in the Item class could be used for the totalPrice).

shop.txt:
123456/Cheerios, 16oz.       /3.69
342313/Tombstone pizza, pep. /5.59
554433/Florida Nat o.j.      /2.29
365365/Fuji apples           /.59/2.34
342313/Tombstone pizza, pep. /5.59
224362/Diet coke, 12 oz. cans/6.89
435435/Oranges, navel        /.79/1.45

Next, read item numbers and percentages from a file called "discount.txt". Each line in the file contains an item number followed by a comma followed by a percentage. Search your array of items for the item number and discount that item by the percentage given. After you have done that for every line in the discount.txt file, print a list of the items again, along with the total price which is now discounted. Finally, print the total amount of money saved after all discounts have been given.

discount.txt:
365365,0.10
342313,0.20
224362,0.15

Sample output for the data given above: .

Shopping Cart

Barcode Item                                                  Price
123456  Cheerios, 16oz.                                       $3.69
342313  Tombstone pizza, pep.                                 $5.59
554433  Florida Nat o.j.                                      $2.29
365365  Fuji apples             2.34 lbs. @ $0.59 per pound   $1.38
342313  Tombstone pizza, pep.                                 $5.59
224362  Diet coke, 12 oz. cans                                $6.89
435435  Oranges, navel          1.45 lbs. @ $0.79 per pound   $1.15

Total Price: $26.58


Shopping Cart

Barcode Item                                                  Price
123456  Cheerios, 16oz.                                       $3.69
342313  Tombstone pizza, pep.                                 $4.47
554433  Florida Nat o.j.                                      $2.29
365365  Fuji apples             2.34 lbs. @ $0.53 per pound   $1.24
342313  Tombstone pizza, pep.                                 $4.47
224362  Diet coke, 12 oz. cans                                $5.86
435435  Oranges, navel          1.45 lbs. @ $0.79 per pound   $1.15

Total Price: $23.17

You saved a total of $3.41

NOTES : You may find that you would like to change your Item class (the one you turned in for program 3). This is fine. It is fine to add methods, and to have methods that are not used in this program. You may implement your array in the driver, which will cause the driver to be rather long, or, you may implement another class to handle the array, much like the CDCollection class in Chapter 7 of the textbook. Either way, be sure your array can handle more items; expand it when necessary. I will test your programs with input files called shop.txt and discount.txt, but they will be different from these files, so don't assume anything about the length of these files.

TURNING IN YOUR PROGRAM: Copy all of your Java files onto neelix. You may have two or three (or possibly even more) depending on how you design your solution. Submit your Item file again, because you may make some changes since program 3.