Question: 1. Which of these classes is a utility class? A. Scanner B. Arrays C. Point D. BankAccount 2. What happens with the following code? Question[]
1. Which of these classes is a utility class?
A. Scanner
B. Arrays
C. Point
D. BankAccount
2. What happens with the following code?
Question[] quiz = new Question[2];
quiz[0] = new ChoiceQuestion();
quiz[0].setText("What is the answer?");
quiz[0].addChoice("42", true);
quiz[0].addChoice("Something else", false);
quiz[0].display()
A. The code does not compile
B. The code compiles but does not display the choices when run
C. The code compiles and runs, but throws an exception when addChoice is called.
D. The program compiles and runs correctly.
3. What is displayed as the result of the following statements?
ChoiceQuestion cq = new ChoiceQuestion();
cq.setText("What is the answer?");
cq.addChoice("42", true);
Question q = cq;
q.display();
A. Nothing is displayed--there is a syntax error.
B. Nothing is displayed--the program crashes when executing one of these statements
C. Only the question text is displayed, not the choices.
D. The question text and choices are displayed.
4. Given the scenario of the preceiding problem, three methods are proposed for the IQuizIO interface:
I: ArrayList readQuiz(String filename)
II: void writeScores(String studentName, int[] scores, String filename)
III: int[] takeQuiz(ArrayList questions)
Which ones would be good choices?
A. I and II
B. I and III
C. II and III
D. All three
5. Given the scenario of the preceding problems, what would be a good implementation for readQuiz method in a MockQuizUI class?
A. readQuiz should be implemented to return null.
B. readQuiz should be implemented to return an empty list.
C. readQuiz should be implemented to return a fixed quiz with a few questions
D. readQuiz should be implemented to read questions from a file provided the file name is quiz.txt
6. Given the scenario of the preceding problems, what would be a good implementations for the writeScores methods in a MockQuizUI class?
A. writeScores should be implemented to do nothing.
B. writeScores should be implemented to write only the name but not the scores of the student
C. writeScores should be implemented to write only the scores but not the name of the student.
D. writeScores should be implemented to write the data only if the file name is scores.txt
7. Given the scenario of the preceding problems, whati s more useful, an interface IQuizUI with a mock implementation, or an interface IQuizIO with a mock implementation?
A. A mock implemenation for IQuizUI is not as useful because input/output is more difficult to implement than the user interface.
B. A mock implementation for IQuizUI is not as useful because input/output can be implemented without taking quizzes, but the user interface requires obtaining a quiz.
C. A mock implementation for IQuizUI is more useful because the user interface is more difficult to implement than input/output
D. Both interfaces are equally necessary because the work is divided among two programmers.
8. Rearrange the following liens of code so that the inner class of the preceding exercise alternately prints "Hello" and changes the button text to read "Say Goodbye", or prints "Goodbye" and changes the button text to read "Say Hello".
^class ClickListener implements ActionListener
+{
+private int counter = 0;
. public void actionPerformed(ActionEvent event
^{
+ counter++
. if (counter % 2 == 1)
+ {
. System.out.println("Hello");
, button.sayText("Say Goodbye");
. }
+ else
+ {
. System.out.println("Goodbye");
, button.setText("Say Hello");
. }
^ }
+}
Why was it necessary for the click listener to be an inner class in the preceding exercise?
A. To have a message printed when the button is clicked.
B. To print alternating "Hello" and "Goodbye" messages
C. To access the button variable in the actionListener method
D. To make the listener class inaccessible outside the main method.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
