Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Lab - 3 Purpose To assess your ability to apply the knowledge and skills developed in Modules 6 and 7 . Emphasis will be placed
Lab
Purpose
To assess your ability to apply the knowledge and skills developed in Modules and Emphasis will be placed on exception handling, binary IO and text IO
Background
Your reputation as a consultant is growing. However, the user interface provided for Books & More has become cumbersome.Further, every time the program starts, some administrative assistant has to reenter all the data! As a result, they just keep the system running and never shut it down. As a result, Books & More has approached you again to modify the system.
Upon consultation with your client, you agree to the following modifications to the system:
Add the ability to load and save the entire product inventory so that records are maintained on disk between program runs.
Add the ability to modify the inventory through a batchdriven text file of commands.
Add the ability to update records one field or more at a time through the command text file.
They eagerly accept your contract, and you are employed for another two weeks!
Assignment
Your job is to make the aforementioned changes to the product. All prior assignments have been bundled into a jar file under libs directory, and so you need only to focus on the BooksAndMore and BatchProcessor classes.
Task : Add persistence to the BooksAndMore class.
Two methods in BooksAndMore need to be implemented. They are, appropriately, readFromFile and writeToFile.Each is described below:
public void writeToFileString fileName
Given a file name, this method should write the contents of the current company out on disk. Any approach can be used as long as the readFromFile method can recreate the company in exactly the same order with exactly the same data. As such, one suggested approach would be to use serialization via the ObjectOutputStream class. This method should not throw any checked exceptions, but in the event that an error occurs, it is permissible to throw an unchecked exception back to the caller.
public static Company readFromFileString fileName
Given a file name, this method should create a new Company object with the data read from the specified file. Any approach may be used; however, the method should be able to reconstruct the Company based on a file created by writeToFile. Note that the method is static, meaning that it can be called without creating a BooksAndMore object.
Note that both writeToFile and readFromFile methods do not declare checked exceptions DO NOT change method signature Therefore, exceptions such as IOException should be handled inside the methods and unchecked exceptions such as RuntimeException may be thrown instead.
To aid with testing system persistence, and to help with working with the system in general, one new method is added to the Company interface. The method is designed to return all products as an array and can be easily used to determine if the contents of the system are as expected.This method will need to be tested and coded.
Task : Implement batch processing via text files.
The command language used for batch processing consists of zero or more lines, each of which contains a command key word followed by one required field and then several optional fields. The command key words are addupdate and delete Any other commands are invalid and should be ignored. The add command should be followed by the type of product and an optional list of field and value pairs for filling in the data of the product. The update command is followed by a required product ID and an optional list of field and value pairs to change. For add and update if no list of fieldvalue pairs exist, the line should also be ignored. The delete keyword is followed only by a required product ID For the delete command, anything following the product ID should be ignored.
Command words are case insensitive in other words, addAdd and ADD should all be interpreted as the add command White space separates the command word from the required parameter and separates the required parameter from any subsequent parameter.
Field and value pairs are separated by commas, and the field and value itself is separated by an equals sign. For example, the following are all valid commands to be found in a file:
ADD Book nameHistoryofFranklin,descFiction,pricequantitydate
Add GiftCard name
G
iftcard,d
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started