Exercise 9AExtend the class
Documentof Exercise 6A with a static method
read(). The method should take a parameter br of type
BufferedReader, read data from br, and create and return a new instance of the class
Document. More precisely, the method
read()should do the following:
;'. The following is an example of a line formatted in such a way:
Bruce Tate;Beyond Java;53
split()method of the class
Documentobject using the information extracted from the line of text, and returns it.
Implement a client of the class
Document that reads a set
Document objects from a given input file, computes the average
number of copies, and writes to and output file all those documents whose
number of copies is greater than the average.
More precisely, the client application should do the following:
Documentobjects of size numDocs.
read(), it reads from the remaining lines of the input file the
Documentobjects and stores them into the array.
Adapt the client application to catch the following exceptions:
FileNotFoundException. The message "The file does not exist" should be displayed.
IOException. The message "The file cannot be read" should be displayed.
NumberFormatException. Occurs when an input file is not formatted correctly, i.e. the first line does not contain an integer representing the number of documents, or an integer representing the number of copies of a document is not present in the required position in a line containing the info for a document. The message "Incorrect formatting: the number of documents or the number of copies is missing" should be displayed
Define a class
DocumentFormatException to represent document
formatting exceptions. Extend the method
read() of the
Document so that it throws this exception in the following
splitmethod. The correct size of the array is 3.
NumberFormatExceptionwhile converting a string into an integer.
Also, modify the client application to catch
DocumentFormatException. If the exception occurs the client
application should do the following:
null. Afterwards, while calculating the average number of copies and writing to the output file, it skips all elements of the array whose value is equal to