Question: Write an application that is including a three-question multiple choice quiz about Java programming language. Each question must have four possible answers (numbered 1 to
Write an application that is including a three-question multiple choice quiz about Java programming language. Each question must have four possible answers (numbered 1 to 4). Also, ask user to type 0 to exit the test. [Assume that a user enters only integers 1,2,3,4, or 0]. Firstly, display a message that this quiz includes three questions about the Java programming language and display that each question has four possible answers.If the answer is correct for the given question, display that the answer is correct. If the answer is not correct for the given question, display that the answer is wrong. If the user answers three questions correctly, display "Excellent", if two, display "very good", if one or fewer, display "It is time to start to learning Java". After that, ask user whether he or she wants to play again [you can use a boolean variable]. If user inputs true, start the game again. If user inputs false, then display a goodbye message and finish the game [Assume that user enters only true or false]. UPLOAD MyTest.java
I typed in the following string is this correct?
// MyTest.java
// Class that represents multiple choice questions
public class MyTest {
// Inputting all required parts of a multiple choice question
private String question; // The question on the test that requires a solution
private String correctAnswer; // The only right answer of the 4 choices
// Choices that contain an answer to a question that has a chance of being the correct answer
private String optionA;
private String optionB;
private String optionC;
private String optionD;
// Constructing each part of a multiple choice question
public MyTest(String question, String correctAnswer, String optionA, String optionB, String optionC, String optionD) {
this.question = question;
this.correctAnswer = correctAnswer;
this.optionA = optionA;
this.optionB = optionB;
this.optionC = optionC;
this.optionD = optionD;
}
// Method that displays the question and choices
public void displayQuestion() {
System.out.println("Question:" + question);
System.out.println("[1]" + optionA);
System.out.println("[2]" + optionB);
System.out.println("[3]" + optionC);
System.out.println("[4]" + optionD);
}
// Predicate method returns the correct answer
public boolean validateAnswer(String answer) {
return correctAnswer.equalsIgnoreCase(answer);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
