Java Test Simulator

Order Description

Background In this assignment you will be implementing the TestSimulator program that performs test simulations for programming quizzes on the command line. The questions are a mixture of multiple-choice and true/false questions. The multiple-choice questions will always have four options of which only one is correct. Some sample data files have been provided in the comma-separated values (CSV) format that will form the question bank that the quizzes are created from. These files are called multiple-choice-questions.csv and truefalse-questions.csv. You can download copies of these from the same place that you downloaded this assignment specification document. The remainder of this assignment specification document is organised as follows: •“Data file formats”: Describes the fields of the two CSV files. •“Class diagram”: Describes the high-level structure of the TestSimulator program. •“Tasks”: Describes the individual tasks of the assignment. Answer them in a sequential fashion. •“Session trace”: Gives some sample output for a finished solution. •“Submission instructions”: Specifies how and where to submit your assignment. •“Marking criteria”: Contains the marking rubric to explain how your marks are earned. Data file formats Each row of the multiple-choice question bank will have the following eight fields: QuestionNum,ChapterNum,Question,Answer1,Answer2,Answer3,Answer4,CorrectAnswer Example: MC001,8,A class that has at least one abstract method is called a:,concrete class,encapsulated class,abstract class,private class,c Each row of the true/false question bank will have the following four fields: QuestionNum,ChapterNum,Question,CorrectAnswer Example: TF001,8,Java allows an instance of an abstract class to be instantiated.,FALSE Notes: •QuestionNum: Unique system-wide identifier. Text format. •ChapterNum: One of 8, 9, 10, 11, 13, 14, 15, 16 only. I.e.: These are the 8 chapters of your Absolute Java eBook that we are practicing in CSE1IOX. Integer format. •Question: Question text. •Answer1/2/3/4: Texts for the four answers for the multiple-choice questions. •CorrectAnswer: Denotes the correct answer. Single-character format for multiple-choice questions: ‘a’ for answer 1, ‘b’ for answer 2, ‘c’ for answer 3 and ‘d’ for answer 4. Alternatively, one of “TRUE” or “FALSE” for true/false questions. Take a moment to inspect the contents of the two question bank files to understand them further. Class diagram The class diagram represents how all classes interact with each other for the final solution. Each component will be introduced in turn in the tasks that follow. Revise your UML learning materials from the CSE1OFX (Object Oriented Programming Fundamentals) subject if you need to refresh some of the notation.

4 Task 1: Program design Create a new NetBeans 8.2 Java 8 project called TestSimulator. Add the eight classes from the UML class diagram in a package called “testsimulator” as shown below.

Create a class stub for each class such as below: public class ClassName { } Add the necessary additional keywords for classes that inherit from interfaces or abstract classes. Task 2: Main menu Consult the UML class diagram and add implementation to the TestSimulator class as follows: getSelection() method: •Print the following menu-based messages: Welcome to the TestSimulator program menu. Select from one of the following options. (1)New test. (2)Test summary. (3)Exit. Enter your selection: •Accept the choice from the user. •Ask the user to enter their choice again if a non-number is received. main() method: •Add a loop that runs the getSelection() method until the user enters option (3). •Add a branching construct that prints a message regarding the user’s choice for each option. •The program finishes normally after option (3) is selected. (Continued on next page.) Task 3: Question class The Question class is an abstract class that represents one question for a test. It contains details about the question, but not much about the answers. This is because there are different types of answers (i.e.: multiple-choice versus true/false) and those details will be implemented elsewhere. Consult the UML class diagram and add implementation to the Question class based on these guidelines: •The isAnswerCorrect() method is an abstract method. I.e.: It has no body. •No further notes are given about the other members (fields, constructors and methods), so use the UML class diagram to guide your implementation. Task 4: MultipleChoiceQuestion class The MultipleChoiceQuestion class adds extra functionality inherited from the Question class to represent one multiple-choice question for a test. It adds extra details about the answers. Consult the UML class diagram and add implementation to the MultipleChoiceQuestion class based on these guidelines: •The isAnswerCorrect() method is overridden from the Question class. It returns true if “correctAnswer” and “chosenAnswer” are the same, otherwise false. •The constructor accepts “answer1”, “answer2”, “answer3” and “answer4” separately, but they are stored together as “answers” of type String[4]. •Field “chosenAnswer” takes a default value of ‘a’, which is the first answer. •No further notes are given about the other members (fields, constructors and methods), so use the UML class diagram to guide your implementation. Task 5: TrueFalseQuestion class The TrueFalseQuestion class adds extra functionality inherited from the Question class to represent one true-false question for a test. It adds extra details about the answers. Consult the UML class diagram and add implementation to the TrueFalseQuestion class based on these guidelines: •The isAnswerCorrect() method is overridden from the Question class. It returns true if “correctAnswer” and “chosenAnswer” are the same, otherwise false. •Field “chosenAnswer” takes a default value of ‘true’, which is the first answer. •No further notes are given about the other members (fields, constructors and methods), so use the UML class diagram to guide your implementation. Task 6: QuestionFinder interface The QuestionFinder interface provides the containsQuestion() method used in the QuestionBank and Test classes. It provides one method with the following definition: public default boolean containsQuestion(String questionID, ArrayList questions) { ... } The method returns true if the “questionID” is found in the “questions” ArrayList, otherwise false. This method is implemented as a concrete method. Concrete methods are allowed in interfaces provided that the default keyword is used. This is a new feature added to Java version 8. 6 Implement the containsQuestion() method in the QuestionFinder interface based on the above guidelines. Task 7: QuestionBank class The QuestionBank class loads all questions from the data files into memory. This allows them to be selected as part of a test later. Consult the UML class diagram and add implementation to the QuestionBank class based on these guidelines: •Remember that a member that is underlined is an instance (static) member. •The QuestionBank constructor includes these important tasks: oCalls loadMultipleChoiceQuestions() and loadTrueFalseQuestions() helper methods. o Prints a message in the form: Loaded all N questions from the question bank. •int getLength(): oReturns the length of the “questions” member. •Question getQuestion(int index): o Returns a Question at the given index. •loadMultipleChoiceQuestions(): o Loads the multiple-choice questions from the data file into the “questions” member. •loadTrueFalseQuestions(): oLoads the true/false questions from the data file into the “questions” member. The loadMultipleChoiceQuestions() and loadTrueFalseQuestions() methods must detect the following error scenarios, implement them with the try/catch mechanism, and print an error message and exit when caught: 1.Could not open a file. 2.File row has incorrect number of fields. 3.chapterNumber field was not numeric. 4.chapterNumber field was not one of the allowed chapter numbers. 5.correctAnswer field was not one of ‘a’ to ‘d’ (for multiple-choice questions). 6.correctAnswer field was not one of ‘true’ or ‘false’ (for true-false questions). 7.questionID is found to be a duplicate. Tips for the loadMultipleChoiceQuestions() and loadTrueFalseQuestions() methods: •Consider the split() method of the String class for separating CSV lines. •Accept the “correctAnswer” field in a case-insensitive way, but always store/process it internally as lowercase for consistency. No further notes are given about the other members (fields, constructors and methods), so use the UML class diagram to guide your implementation. Task 8: QuestionBank milestone This task is a chance to pause your implementation and test your work from Tasks 3-7 before proceeding further: •Create an instance of the QuestionBank class at the beginning of your main() method in the TestSimulator class. •Run your program. •Your code should print the message from the QuestionBank constructor indicating that your work is successful so far: “Loaded all N questions from the question bank.” Task 9: Test class The Test class creates a test using a random subset of questions from the QuestionBank. It also includes functionality to run the test, show a summary of results, and save the results to file. Consult the UML class diagram and add implementation to the Test class based on these guidelines: •The Test constructor includes these important tasks: oCall the selectQuestions(int numQuestions) helper method. o The program will continue and print the following messages if the QuestionBank has fewer questions than requested: The question bank does not have M questions. The test will have N questions instead. •int getLength(): oReturns the length of the “questions” member. •selectQuestions(int numQuestions, questionBank QuestionBank): oRandomly selects the appropriate number of questions from the question bank to be the test. Avoids duplicates. •runTest(): oRuns the test in an interactive fashion one question at a time. o Reprompts for invalid answers. oAllows quitting any time with ‘q’. Progress and results will not be saved. o Gives instantaneous feedback after each question. oImportant: You need to replicate the output from the “Session trace” section. •showTestSummary(): oPrints a short summary of performance for the current test in the following format: You answered M questions correctly out of N. Your score was XX.XX%. •saveTestResult(): oSaves results in two files: ▪Test result file: test-yymmdd-hhmmss.txt (where yymmdd-hhmmss is the current date and time). ▪Test summary file: test-summary.txt o The test result file uses the following format (one question per line): questionID,chapterNumber,correctAnswer,chosenAnswer oThe test summary file stores the names of all previous test result files. oFile errors must be caught, and the program must be terminated with an appropriate error message. oAll files are saved at the top level of your NetBeans project. This is the default location. oPrints the following message on success (example provided): Test result saved to test-180612-110754.txt. Test record added to test-summary.txt. Tips for implementing the Test class: •The “instanceof” operator can be helpful to check if you are dealing with a MultipleChoiceQuestion or a TrueFalseQuestion. •Consider casting as necessary to go from a general Question object to a specific question object such as: ((MultipleChoiceQuestion)question).getCorrectAnswer() •Try LocalDateTime.now() to get the current date and time. •Try DateTimeFormatter.ofPattern("yyMMdd-HHmmss") to get the timestamp in the requested format. No further notes are given about the other members (fields, constructors and methods), so use the UML class diagram to guide your implementation. 8 Task 10: Test milestone This task is another chance to pause your implementation and test your work from Task 9 before proceeding further. The following implementation will replace the “(1) New test” option in the TestSimulator class: •Create a Test object with numQuestions = 5. •Call the runTest() method. •Proceed with the following if runTest() returned true only: oCall the showTestSummary() method. oCall the saveTestResult() method. Task 11: TestSummary class The TestSummary class calculates and prints the summary of performance of all previously recorded test results. Consult the UML class diagram and add implementation to the TestSummary class based on these guidelines: •summarisePerformance(): oOpens the test summary file. Opens each test report file found in turn. oCalculates the number of questions correct and number of questions answered for all the chapter topics. Calculation results are stored in the corresponding class fields. •reportPerformance(): oPrints a summary of all test performance to screen. o Performance is on a chapter-by-chapter basis, plus totals at the bottom. o Report columns use a fixed-width format with the System.out.printf() method. oImportant: You need to replicate the output from the “Session trace” section. The summarisePerformance() method must detect the following error scenarios, implement them with the try/catch mechanism, and print an error message and exit when caught: 1.Could not open a file. 2.File row has incorrect number of fields. 3.chapterNumber field was not numeric. 4.chapterNumber field was not one of the allowed chapter numbers. No further notes are given about the other members (fields, constructors and methods), so use the UML class diagram to guide your implementation. Task 12: TestSummary milestone This is the final coding task. The following implementation will replace the “(2) Test summary” option in the TestSimulator class: •Create a TestSummary object. •Call the summarisePerformance() method. •Call the reportPerformance() method. Task 13: Testing Identify (but do not implement) a new feature that could hypothetically be added to the TestSimulator program. Answer the following questions about this feature: a)Briefly describe how you would test this feature with black-box testing. b)Briefly describe how you would test this feature with white-box testing. c)Briefly describe a unique error scenario that may come up if your feature was implemented. d)Design a custom Java class to represent a custom exception for (c). Your solution must follow best-practices from Java’s Exception class hierarchy including: •A default constructor. •A one-argument constructor with a message. •The getMessage() accessor method. To help you out, here is a list of pre-approved features that you could design your answer on: •A test for a user-specified chapter. •A test that omits questions from the previous X attempts. •A test summary for a user-specified date range. •A feature to delete a user-specified test record. Session trace The following session trace demonstrates the three main menu options in turn: Loaded all 32 questions from the question bank. Welcome to the TestSimulator program menu. Select from one of the following options. (1)New test. (2)Test summary. (3)Exit. Enter your selection: 1 Welcome to your test. The test will have 5 questions. You may hit 'q' to quit the test any time, but progress or results will not be saved. Starting your test now ... Question 1: A linked data structure contains nodes and links. (a)True (b)False Enter your answer: a Feedback: Correct! Question 2: A class with no abstract methods is called a: (a)concrete class (b)encapsulated class (c)abstract class (d)private class Enter your answer: d 10

Feedback: Incorrect. Correct answer was (a). Question 3: A class that has at least one abstract method is called a: (a)concrete class (b)encapsulated class (c)abstract class (d)private class Enter your answer: c Feedback: Correct! Question 4: The binary search algorithm is extremely slow compared to an algorithm that simply tries all array elements in order. (a)True (b)False Enter your answer: b Feedback: Correct! Question 5: The stream that is automatically available to your Java code is: (a) System.out (b) System.in (c)System.err (d)All of the other options Enter your answer: d Feedback: Correct! Test is finished. You answered 4 questions correctly out of 5. Your score was 80.00%. Test result saved to test-180612-121555.txt. Test record added to test-summary.txt. Welcome to the TestSimulator program menu. Select from one of the following options. (1)New test. (2)Test summary. (3)Exit. Enter your selection: 2 Performance report ... Chapter Correct Answered Percent -------- -------- -------- -------- 83 6 50.00 91 2 50.00 101 2 50.00 114 5 80.00 131 1 100.00 143 4 75.00