A quiz consists of a sequence of questions—in our case, ChoiceQuestion
objects. We'll assume a quiz never has more than 100 questions. Quizzes can be read in from a file, such as this one:
What trademarked slogan describes Java development? Write once, ... *run anywhere debug everywhere run many times read anywhere What are the first 4 bytes of every class file (in hexadecimal)? The ASCII codes of the letters JAVA *0xCAFEBABE 0xCAFEDEAD 0xDEADBEEF What is the original name of the Java language? *7 C-- *Oak Gosling
We assume that each question has exactly four choices. The first line of each question is the question text. Then there are four lines of choices. The correct choice starts with a *
as the first character. Note that in the last question, where one of the choices is *7
(which, as it happens, was the name of the venture tasked with marketing an early Java effort), the *
is preceded by a space so that it isn't interpreted as the correct choice.
Questions are separated by blank lines, except there is no blank line at the end of the file.
The readQuestions
method reads in a quiz with questions in this format.
The presentQuestions
presents the quiz questions to a user.