Question
***NETBEANS JAVA 2 Consider the following UML diagram and use it to create all classes (the driver, Midterm2019.java is given below with a sample run).
***NETBEANS JAVA 2
Consider the following UML diagram and use it to create all classes (the driver, Midterm2019.java is given below with a sample run). Note: InterfaceQuestion is an Interface, Question is a class that accepts a String as answer to a question, ChoiceQuestion is a multiple-choice question with only one answer, MultiChoiceQuestion allows for multiple answers, and NumericQuestion allows for numeric answers with error tolerance of 0.01.
Here is the code for the InterfaceQuestion:
package Midterm;
public interface InterfaceQuestion
{
public abstract void setText(String questionText);
public abstract void setAnswer(String correctResponse);
public abstract String getName();
}
package Midterm;
import java.util.Scanner;
/* A quiz consists of questions, and there are different kinds of questions:
Fill-in-the-blank
Choice (single or multiple)
Numeric (where an approximate answer is ok; e.g., 1.33 when the actual answer is 4/3)
Free response */
public class Midterm2019
{
private static final byte NUMBER_QUESTIONS = 5;
public static void main(String[] args)
{
InterfaceQuestion[] quest = new InterfaceQuestion[NUMBER_QUESTIONS];
Question question = new Question();
Scanner keyboard = new Scanner(System.in);
question.setText("Who was the inventor of Java?");
question.setAnswer("James Gosling");
ChoiceQuestion first = new ChoiceQuestion();
first.setText("What was the original name of the Java language?");
first.addChoice("*7", false); first.addChoice("Duke", false);
first.addChoice("Oak", true);
first.addChoice("Gosling", false);
ChoiceQuestion second = new ChoiceQuestion();
second.setText("In which country was the inventor of Java born?");
second.addChoice("Australia", false);
second.addChoice("Canada", true);
second.addChoice("Denmark", false);
second.addChoice("United States", false);
MultiChoiceQuestion third = new MultiChoiceQuestion();
third.setText("Suppose A is an abstract class, B is a concrete " +
"subclass of A, and both A and B have a no-arg constructor. " + "Which of the following is correct?");
third.addChoice("A a = new A();", false);
third.addChoice("A a = new B();", true);
third.addChoice("B b = new A();", false);
third.addChoice("B b = new B();", true);
MultiChoiceQuestion fourth = new MultiChoiceQuestion();
fourth.setText("Which of the following are incorrect?");
fourth.addChoice("An abstract class contains constructors.", false);
fourth.addChoice("The constructors in an abstract class should be protected.", false);
fourth.addChoice("The constructors in an abstract class are private.", true);
fourth.addChoice("You may declare a final abstract class.", true);
fourth.addChoice("An interface may contain constructors.", true);
quest[0] = question;
quest[1] = first;
quest[2] = second;
quest[3] = third;
quest[4] = fourth;
for(int i = 0; i
presentQuestion((Question)quest[i]);
}
public static void presentQuestion(Question quest)
{
quest.display();
System.out.print("Your answer: ");
Scanner in = new Scanner(System.in);
String response = in.nextLine();
System.out.println(quest.checkAnswer(response) + " ");
}
}
run:
Who was the inventor of Java?
Your answer: James Gosling
true
What was the original name of the Java language?
1: *7
2: Duke
3: Oak
4: Gosling
Your answer: 3
true
In which country was the inventor of Java born?
1: Australia
2: Canada
3: Denmark
4: United States
Your answer: 2
true
Suppose A is an abstract class, B is a concrete subclass of A, and both A and B have a no-arg constructor. Which of the following is correct?
1: A a = new A();
2: A a = new B();
3: B b = new A();
4: B b = new B();
There are several correct answers, list all of them separated by spaces.
Your answer: 2 4
true
Which of the following are incorrect?
1: An abstract class contains constructors.
2: The constructors in an abstract class should be protected.
3: The constructors in an abstract class are private.
4: You may declare a final abstract class.
5: An interface may contain constructors.
There are several correct answers, list all of them separated by spaces.
Your answer: 3 4 5
true
BUILD SUCCESSFUL (total time: 17 seconds)
***NETBEANS JAVA 2
Midterm2019 InterfaceQuestion NUMBER QUESTIONS byte 5 + main args:String vo +presentQuestion(quest Question) void Question text String - answer String + Question + setText questionText: String) void + setAnswer(correctResponse: String): void + checkAnswer(response String): boolean display0:void getNameO:String ChoiceQuestion + ChoiceQuestion +addChoice(choice:String, correct: boolean): void + display0 void +getName0 String MultiChoiceQuestion NumericQuestion +MultiChoiceQuestion - answer double setAnswer(correctResponse: String) void + checkAnswer(response: String): boolean + display0 void +getName0 String + setAnswer(correctResponse double) void +checkAnswerresponse String): boolean +getName0 String Here is the code for the InterfaceQuestion: package Midterm; public interface InterfaceQuestion public abstract void setText(String questionText) public abstract void setAnswer(String correctResponse); public abstract String getName Midterm2019 InterfaceQuestion NUMBER QUESTIONS byte 5 + main args:String vo +presentQuestion(quest Question) void Question text String - answer String + Question + setText questionText: String) void + setAnswer(correctResponse: String): void + checkAnswer(response String): boolean display0:void getNameO:String ChoiceQuestion + ChoiceQuestion +addChoice(choice:String, correct: boolean): void + display0 void +getName0 String MultiChoiceQuestion NumericQuestion +MultiChoiceQuestion - answer double setAnswer(correctResponse: String) void + checkAnswer(response: String): boolean + display0 void +getName0 String + setAnswer(correctResponse double) void +checkAnswerresponse String): boolean +getName0 String Here is the code for the InterfaceQuestion: package Midterm; public interface InterfaceQuestion public abstract void setText(String questionText) public abstract void setAnswer(String correctResponse); public abstract String getNameStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started