Part I: Project Introduction In this exercise you will use an abstract class to define, read, store, and print questions for a test. Note that a test may have questions such as an essay, a multiple choice question, fill in the blanks etc etc. Thus, a “test question ” can be defined as an abstract class in Java programming. For this project, you will start by writing an abstract TestQuestion class. Then you will extend the TestQuestion class to define specific classes such as an Essay class, and a MultChoice class, which implement the abstract methods. You will read the test questions from an input file. The input file will consist of information about the various types of test questions using a specific format. After you read and process the data in the input file, you will create and print the corresponding quiz. Please study the following Sample input file and sample quiz below very carefully before you write the classes. Sample input file: Assume that the input file consists of the following data: The very first item of input, before any questions, is an integer indicating how many questions will be entered. o type of question (character, m=multiple choice, e=essay) o if the question is an essay (e) , then we read the number of blank lines for essay in the next line (an integer) o if the question is an multiple choice question (m) , then we read the number of choices for the question in the next line (an integer) • Then we read the multiple choice question followed by the choices: • choice 1 (multiple choice only) • choice 2 (multiple choice only) • choice 3 (multiple choice only) • etc.. For example, for the following three questions: an essay question requiring 5 blank lines, a multiple choice question with 4 choices, and another essay question requiring 10 blank lines: the input file may have the following data: 3 e 5 Why does the constructor of a derived class have to call the ….? m 4 Which of the following is not a legal identifier in Java? guess2 2ndGuess _guess2_ Guess e 10 How do interfaces provide polymorphism in Java? And the sample quiz using the above input file with 3 questions would be printed as follows: ________________________________________ 1.Why does the constructor of a derived class have to call the …? 2.Which of the following is not a legal identifier in Java? a. guess2 b. 2ndGuess c. _guess2_ d. Guess 3.How do interfaces provide polymorphism in Java? Part II: Project Functionality ( 130 Points) Here are the classes that you need for the project: TestQuestion class( 6 pts): (6 points)First, write an abstract class TestQuestion that contains the following: • (3 pts)A protected String variable that holds the test question. • (3 pts) An abstract method protected abstract void readQuestion( Scanner input ) to read the question from the input file. The method readQuestion must be abstract because different test questions can be read using different algorithms from a given input file. For example, an essay requires only a space besides the question whereas a multiple choice question requires various choices to choose from besides the question. The readQuestion method should have only one parameter. The parameter is an object such as a Scanner object or a BufferedReader object to read the question correctly from an input file. • (Optional) You may have one other method in the TestQuestion class. It could be toString() method inherited from the Object class. • Recommendation – compile the class and correct any errors if necessary. Essay and MultChoice classes ( 59 pts) (59 points)Now define two subclasses of the TestQuestion class: Essay and MultChoice. • ( 25 pts)Essay class will need the following: o ( 3 pts)an instance variable ( private) to store the number of blank lines needed after the question (answering space). o ( 16 pts)Implement the readQuestion method to read data from the input file o ( 6 pts)The class also has a method to display the complete question ( i.e. the question and the blank lines). Override the toString method of the Object or TestQuestion class to return nicely formatted versions of a question. o Recommendation – compile the class and correct any errors if necessary. Write a small driver program and test with an input file with only essay questions. • (34 pts) MultChoice will need the following: o ( 4 pts)It will need an array of Strings ( private) to hold the choices along with the main question. ( i.e. the question and the choices). o (24 pts)Implement the readQuestion method to read data from the input file o ( 6 pts)The class also has a method to display the complete question ( i.e. the question and the choices). Override the toString method of the Object or the TestQuestion class to return nicely formatted versions of the question. (e.g., the choices should be lined up, labeled a), b), etc, and indented in MultChoice).
Driver class: (65 Points)Now define a driver class WriteTest to test the classes..
( 5 pts)Start by creating a generic ArrayList object to hold the various TestQuestion objects (Essay or MultChoice objects).
(10 pts)Read data from the input file. The first data reading is an integer that indicates how many questions are coming. Then according to the type of the test question, you should create a MultChoice object for each multiple choice question or an Essay object for each essay question, and
( 10 pts)Save each object in the ArrayList object.(note that both Essay and MultChoice are subclasses of TestQuestion class, and objects of both types can be stored in the TestQuestion generic ArrayList object.)
( 20 pts)When all of the data has been read, use a loop to print the questions from the ArrayList object, numbered, in order on the screen and print the generated quiz to a quiz.txt output file.
For one of your tests, use the attached file testbank.dat .
(20 Points)Make sure that the application handles any exceptions that may occur while reading the input file. Test the application with different input files. First test the program with 3 questions. Then use the data in testbank.dat to test your program, which has 10 questions. Finally test the application with other input files such as an input file, which is missing the number of lines for an essay question.
If the input file does not exist, the program should indicate this to the user and may prompt the user to enter another input file name or abort the program indicating the error. If the input file has incorrect data, the program should end indicating an I/O error.