I got the quiz displayed and everything works just fine. However, I can't use 0 to exit the quiz, and at the end, I don't know how to use boolean value to ask the users if they want to do the quiz again or not. I have to have 0 in each question. This is my prompt
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 the 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 the correct answer. 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]
What I have tried:
Here is my code
import java.util.Scanner;
public class MyTest {
public static void main (String [] args) {
System.out.println("\t\t\t**This is a Java programming quiz**");
System.out.println("\tThere are 3 questions and each question has 4 possible choices");
System.out.println();
myTest();
goodBye();
}
public static void myTest() {
Scanner input = new Scanner (System.in);
System.out.println("\t 1)Which of the following will declare an array and initialize it with 5 numbers: ");
System.out.println("\t 1) Array a = new Array(5);");
System.out.println("\t 2) int[] a = {23, 22, 21, 20,19};");
System.out.println("\t 3) int a[] = new int [5];");
System.out.println("\t 4) int[5] array;");
System.out.print("\tChoose the best answer: ");
int choice1 = input.nextInt();
if (choice1 == 2){
System.out.println("\tThat's correct!");
}
else{
System.out.println("\tThat's not correct. The correct answer is int[] a = {23, 22, 21, 20,19};");
}
System.out.println();
System.out.println(" \t2)Which of the following is a valid declaration of a boolean: ");
System.out.println("\t 1) boolean b1 = 0;");
System.out.println("\t 2) boolean b2 = 'false'; ");
System.out.println("\t 3) boolean b3 = false;");
System.out.println("\t 4) boolean b4 = no;");
System.out.print("\tChoose the best answer: ");
int choice2 = input.nextInt();
if (choice2 == 3){
System.out.println("\tThat's correct!");}
else{
System.out.println("\tThat's not correct. The correct answer is boolean b3 = false;");
}
System.out.println();
System.out.println("\t3)Which of the following is function overloading: ");
System.out.println("\t 1) Methods with same name but different parameters.");
System.out.println("\t 2) Methods with same name but different return types.");
System.out.println("\t 3) Methods with same name, same parameter types but different parameter names.");
System.out.println("\t 4) None of the above.");
System.out.print("\tChoose the best answer: ");
int choice3 = input.nextInt();
if (choice3 == 1){
System.out.println("\tThat's correct!");}
else{
System.out.println("\tThat's not correct. The correct answer is Methods with same name but different parameters");
}
if (choice1 == 2 && choice2 == 3 && choice3 == 1){
System.out.println("\tExcellent!");}
else if ((choice1 == 2 && choice2 == 3) || (choice1 == 2 && choice3 == 1)||(choice2 ==3 && choice3==1)){
System.out.println("\tVery good!");}
else if(choice1 == 2 || choice2 == 3 || choice3 ==1){
System.out.println("\tIt is time to start to learning Java!");}
System.out.println("Do you want to play again? Enter True or False: ");
boolean again = input.nextBoolean();
}
public static void goodBye() {
System.out.println("Goodbye! Exiting......");
}
}