The loadfiledatacleanly method should replace any contents


Tasks

1. Download the provided zip file, extract it to your workspace, add the project to the workspace, and look at the contents.

2. In particular, consider the file clothing.txt which contains a set of records representing items of clothing that are for sale by a retail outlet.

The file's contents follow a specific format: The first line of the file is an int value, specifying how many records will follow in the file after that line. Each of the records consists of 3 separate lines. The first line of three for each record is the description of the clothing item, the second line is the price of the item, and the third line represents a quantity that is in stock at the shop.

The clothing items can be represented in the program by objects of the ClothingItem class type, which has been provided to you. Ensure that you understand how to use the ClothingItem class.

3. Start to write a RetailShop class that includes the features described below. Remember that you will probably need to include some exception handling code. As you come to each task, you might want to update a separate Driver class (see task 4) to make sure it calls the method, and tests that the method is working correctly:

a. The constructor of RetailShop should create an ArrayList in which details of all the items of clothing will be stored. Initially (at constructor time) there should be no items. Ensure that the driver class creates an object of the RetailShop type, which will be used for calling the subsequent methods.

b. The loadFileDataCleanly( ) method should replace any contents that are in the ArrayList, with ClothingItem objects created from data which is read in from the clothing.txt file. Ensure that your driver class calls this method before any of the remaining methods or described behaviour is done.

c. The showItems( ) method should display each of the ClothingItems that the shop sells, reporting all details about each, including the quantity currently in stock.

d. The reportOutOfStock( ) method should display the same information as for showItems( ) except that the output should be written to a text file named report.txt, and it should only include those ClothingItems for which the quantity has reached 0.

e. The addNewItem( ) method should accept a ClothingItem object reference as the parameter, and if it has a valid value it will store this item at the end of the ArrayList after the existing items.

f. The saveItemsBinary( ) method should save the current state of all items that are in the ArrayList (including any that have been added by task e), to a binary file named items.dat, using techniques for serialization. If you need to alter any of the provided code to achieve this task, that is fine.

g. The loadItemsBinary( ) method should restore the state of the ArrayList to be referring to the same objects that it had at the time the data was serialized. So for example, if the first item was "Summer Dress with Flower patterns" and there was a quantity of 4 of them at serialization time, then after this method is called, the system would report that there are just 4 "Summer Dress with Flower Patterns" in stock. The only items that should be in the ArrayList, are the ones that were previously serialized.

4. Commence writing a text-menu-based driver class that starts by creating a new RetailShop object, and then address the following aspects. Note that it may require you to make further adjustments to the RetailShop class:

a. Initially, the RetailShop object should fill itself with data about items of clothing read in from file. It should aim to read the data from the binary file, but if that is missing it should try to load the initial data cleanly from the text file. If it can't read even from that text file, it should tell the user how to fix the problem, and exit.

b. One of the actions on the menu should call the showItems( ) method to show on the screen details about all the items of clothing normally sold.

c. Another of the actions on the menu should call the reportOutOfStock( ) method, to produce the text file containing the report of sold-out things.

d. Another of the actions on the menu should be to Exit the program. If this is selected, the program should save the current data about clothing items to a binary file, so that next time the program is started, that data can be restored from the binary file and the program can continue on as though it had never ended.

e. Another of the actions on the menu should be to "Sell an item of clothing". This should first present the user with a list of all the clothing items that are sold by the shop, and then ask the user to select one. If there is at least one of the selected item in stock, then the program should display a message indicating success and reduce the quantity in-stock by one - otherwise, report a suitable message to the user.

f. Another of the actions on the menu should allow the user to alter the price of any existing item of clothing. It should first present the user with a list of all the clothing items that are sold by the shop, and then ask the user to select one. Then it should ask the user to specify the new price, and make relevant changes to the system to ensure that the new price is thereafter used for the selected clothing item.

g. Another of the actions on the menu should allow the user to specify the details of a new item of clothing that the shop will sell, and record the information in memory. Thereafter, that new clothing item will be included in reports, lists, etc., including on future runs that load data from the binary file.

Request for Solution File

Ask an Expert for Answer!!
Other Subject: The loadfiledatacleanly method should replace any contents
Reference No:- TGS01112026

Expected delivery within 24 Hours