Java代写:CST8284 Quiz Master

用Java代写一个选择题的答题器程序,练习基本的程序设计。

Description

The purpose of this assignment is to build an application that

  1. Locates a .quiz file on your hard drive and opens it
  2. Reads each of the objects in that file into an array (for easier handling)
  3. Each object contains a question and an array of possible answers, along with the correct answer, the difficulty level, the number of points awarded, etc. Therefore, each pane will need to display this information into the pane
  4. The code loops through the array of objects, and on each iteration displays a new Q/A combination. The program terminates when the questions are finished, and displays the number of correct responses out of the total number of questions asked.

QuizMaster

Load the code for this lab, available on Blackboard, into a new project

  • In Eclipse, create a new project called Assignment1
  • Download Assignment1.zip from Blackboard and open the contents into a package

Review the files in Assignment1.zip and make sure you understand their purpose

There are four files included with this assignment, which you must use, and which you must submit with your finished assignment.
QuizMain is the main point of entry for your program. It performs three main actions: it loads a simple splash pane (given); it opens the file containing the Q/A objects and loads them into an array, and then loops through the array loading each question into a BorderPane with separate sections for the question, answers, and explanation; and finally displays the results of the quiz.

Note that each of the three sections is associated with a method that loads up a different Pane object. getSplashPane() loads a simple text message (“Welcome to QuizMaster”) for initial display in the centre of a BorderPane. getCurrentQAPane() uses the current QA object to load up a BorderPane with some of the components of the QA object. getResultsPane() displays the results of the quiz. getSplashPane() is provided for you; more information on the other two panes is provided below.

FileUtils is a class containing static methods that perform basic file I/O operations, including checking to see if the file exists, returning the file name, and so on. The static method getFileHandle() calls up the FileChooser dialog box, shown below, which prompts the user to select a .quiz file (to be provided), which contains the QA objects to be loaded. Note that the other utilities in this class rely on a file having been correctly selected. If the ‘Cancel’ button on the dialog is selected, then no file handle is returned from getFileHandle(), and any further attempts to return a path name to the file return an empty string.

If they do wish to continue, then prompt them with the above dialog again, otherwise execute Platform.exit() to exit the program.

The code in FileUtils is mostly complete, with the exception of the getQAArray() method, which you’ll need to supply. This method reads in the absolute path of the file returned from getFileHandle() - you can use getFileName() to return this string, assuming it was correctly supplied by the user—and loads each object into an array of QA objects, which gets returned to the user.

QuesAns is an abstract class that lists the abstract methods required elsewhere in your program.

QA extends QuesAns and supplies concrete methods. Use the QA class when you need to load the QA objects from the .ques file returned by getFileHandle(), as indicated above in part (b), and when you need to load the currentQAPane, as indicated below

Supply the classes/methods required to allow for the correct execution of your program

Note that the method FileUtils.showAndWait(FileUtils.ON) effectively pauses the program to give the user time to input a response. Without such a mechanism, the enhanced for loop that drives the program would simply loop through and load every pane in rapid succession, with no way to allow the user time to read questions and select answers.

There are better ways to perform this operation, but they involve code that is beyond our reach just now. For now, showAndWait() does the job. Therefore, when the user wishes to move on to the next question, the NEXT QUESTION button must execute FileUtils.showAndWait(FileUtiles.OFF), to allow the program to load the next QA object in the loop.

Also note that, for demonstration purposes, the .ques file will only contain MAX_QA_SIZE questions (initially set to 5); hence we only load MAX_QA_SIZE objects into the array, and loop through the enhanced for loop MAX_QA_SIZE times. This will change in Assignment 2 when we modify this code to accommodate files of any size.

Aside from the getQAArray code needed to complete the FileUtils class, along with the code needed to display the results at the end of the program, most of your time will be spent writing the code needed to display the current Question/Answers combination.

The getCurrentPane() method, which reads in the currentQA object, should be included in QuizMain, along with the two other ‘getPane()’ methods needed for proper execution of the program.

Your QA input pane should look something like the screenshot shown in the figure below.

Note however that you have considerably flexibility in how you choose to present this information, including which type of pane(s) you use, which fonts, etc. There are some things which you must do however:

  • The output should be positioned in the middle of the window
  • The text output should maintain its general features when resized (e.g. to full screen)
  • When the Check Answer button is selected, it should indicate in the space below the answers (a) which answer is correct, displaying the currentQA.explanation() String into the bottom of the screen to explain why the answer was correct or incorrect (not shown above).
  • In the Next Question event handler, set FileUtils.waitAndShow(OFF). This should allow your program to move on to the next QA object, thereby loading the next question into the pane.
  • You must use Radio Buttons for the Answers section of the pane, and this will require that you construct a new class, called AnswerPane, described next.

The AnswerPane class stores all the information needed to load and display the answers, as well as record which one of the radio buttons was selected. The UML diagram for AnswerPane is shown below.

Note the follow features of AnswerPane:

  • It contains four private members, including: an array of strings corresponding to the array of possible answers; an array of radio buttons whose number will be determined by the number of answers in the array of Strings just mentioned; a ToggleGroup object, which is a container for the radio buttons (see below); and a VBox, which aligns the radio buttons, togglebox, and strings, and its returned by the getAnswerPane() method for display.
  • The AnswerPane() constructor takes in an array of strings corresponding to the answers for each question. You do not need a no-arg constructor, as this class will not be extended in a subclass (you need to ensure this in your code how?)
  • getAnswerPane() adds radio buttons to the answerBox pane and returns the answerBox pane to the calling program. The number of radio buttons will be equal to the number of answers in string supplied with the AnswerPane() constructor. Each radio button must be part of the
    ToggleGroup previously mention. (A ToggleGroup ensures that only one button can be selected at any time. Thus this program is not designed to handle multiple answers, only single answers.) For information on adding radio buttons to a toggle group.

The getButtonSelected() method should loop through the array of radio buttons and use the radio button’s isSelected() property to determine which button was chosen by the user.

The Check Answer button is not part of the AnswerPane, however it relies on an instance of the AnswerPane object to (1) get the answer selected by the user using getButtonSeleted() (2) compare this with the correct answer, as provided by the QA object (3) store the result in the QA object using the setResult() method, true if the answer was correct and false otherwise (4) Load the response string beneath the answers so the user can check the results.

The resultsPane() loops through each QA object reports constructs a text string for display in the pane returned by this method. The text should indicate (1) the question number (2) whether the answer with CORRECT or WRONG, and (3) at the very end, the total score, based on the total number of correct answers divided by the total number of questions.