Question

Write a java application that is including a three-question multiple choice quiz about Java programming language....

Write a java 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]. name the file MyTest.java

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution : To implement the java quiz application , we will take the integer input values from the user using the scanner class.We will make use of a while loop which runs the quiz until the user inputs the value true or else the program the terminates .If at any instant the user wants to exit the quiz he or she must press 0, then the break statement will be executed and the progam will terminate.

Code :

import java.util.Scanner;

public class MyTest {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        boolean flag = true;
        while (flag) {
            System.out.println("This quiz contains three questions about java programming language and each question has four possible answers.");

            int correct = 0;
            System.out.println("Question 1: Which component is used to compile, debug and execute java program?\n" +
                    "1) JVM\n" +
                    "2) JDK\n" +
                    "3) JIT\n" +
                    "4) JRE\n" +
                    "enter 0 to exit the test");

            int userInput = s.nextInt();
            if (userInput == 2) {
                System.out.println("Answer is correct");
                correct++;
            } else if (userInput == 0) {
                break;
            } else {
                System.out.println("Answer is wrong");
            }
            System.out.println("Question 2: Which statement is true about java?\n" +
                    "1) Platform independent programming language\n" +
                    "2) Platform dependent programming language\n" +
                    "3) Code dependent programming language\n" +
                    "4) Sequence dependent programming language\n" +
                    "enter 0 to exit the test");
            userInput = s.nextInt();
            if (userInput == 1) {
                System.out.println("Answer is correct");
                correct++;
            } else if (userInput == 0) {
                break;
            } else {
                System.out.println("Answer is wrong");
            }
            System.out.println("Question 3: Which of the following is a valid declaration of an object of class Box?\n" +
                    "1) obj = new Box();\n" +
                    "2) Box obj = new Box;\n" +
                    "3) Box obj = new Box();\n" +
                    "4) new Box obj\n" +
                    "enter 0 to exit the test");
            userInput = s.nextInt();
            if (userInput == 3) {
                System.out.println("Answer is correct");
                correct++;
            } else if (userInput == 0) {
                break;
            } else {
                System.out.println("Answer is wrong");
            }

            if (correct == 3) {
                System.out.println("Excellent!");
            }
            if (correct == 2) {
                System.out.println("Very good!");
            }
            if (correct <= 1) {
                System.out.println("It is time to start learning java!");
            }

            System.out.println("Do you want to play again?");
            flag = s.nextBoolean();
            if (flag) {
                continue;

            } else if (flag == false) {
                System.out.println("Goodbye");
                break;
            }
        }
    }
}

Output 1 :

Output 2 :

Add a comment
Know the answer?
Add Answer to:
Write a java application that is including a three-question multiple choice quiz about Java programming language....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT