NOTE 1: Use the class names and method signatures exactly as given in the following descriptions.
We'll be running your code with our own main program that will rely on the given names and signatures. Put each class
in its own file. All classes should be part of a package named quizPackage
.
NOTE 2: Document all classes and methods with javadoc-style comments.
Question
. A question consists of a question (naturally!), an associated
correct answer, and a level of difficulty. The difficulty level should be implemented as an enumerated type (called
Difficulty
), where the
values of the type are EASY and HARD.
Quiz
. A quiz consists of an ArrayList<Question>. You may find you need
to add other
private fields to the Quiz class as you develop methods for quizzes.
toString()
method in the Question class. You may
define additional methods
in the Question class as needed.
add()
in the Quiz class. The method adds the given question to the
ArrayList of questions in the quiz.
giveQuiz()
in the Quiz class. There should be two versions of this method.
One version, which doesn't take any parameters, cycles through all the questions in the quiz, asking each question,
accepting the user's response, and reporting whether or not the answer was correct. After all questions have been
asked and answered, the method calculates and displays the user's score as a percentage. (See Sample Output, below).
The second (overloaded) version of the giveQuiz()
method takes a single parameter of type Difficulty
, and should
work the same as the first version, except that only those questions with the given difficulty level are asked.
QuizTime
that consists of a main method that populates a Quiz
with Questions, then administers the quiz.
<...preparing quiz...> Type A to see All questions in the quiz Type E to see only the Easy questions Type H to see only the Hard questions Enter your choice (A, E, H) now: A An interface can contain method definitions (true/false) true No, the answer is false What keyword is used in Java to indicate that a field is accessible only to objects in its class? private Correct! If a field is private in a superclass, can it be declared public in a subclass (yes/no) yes No, the answer is no Your score is 33.33%
<...preparing quiz...> Type A to see All questions in the quiz Type E to see only the Easy questions Type H to see only the Hard questions Enter your choice (A, E, H) now: E An interface can contain method definitions (true/false) false Correct! What keyword is used in Java to indicate that a field is accessible by name only to objects in the same class? public No, the answer is private Your score is 50.00%
Export your Eclipse project to a zip file and submit the zip file via web-based turnin. To export a project, go to File | Export… and choose Archive File from the General folder. Check off the entire project in the top left window and make sure the format is .zip and not .tar. Finally, give the archive file a name and click finish.
The name of the turnin project is Homework 2.
Programs submitted after 5pm on March 31 will be tagged as late, and will be subject to the late homework policy.