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
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 :
Write a java application that is including a three-question multiple choice quiz about Java programming language....
Java Programming Write a program that will help a student learn multiplication. Use SecureRandom object to produce two positive integers between 1 and 20. The program should then prompt the user with a question (use a sentinel-controlled loop), such as: How much is 10 times 11? The student then inputs the answer. If the answer is correct display the message “very good” and ask another question. If the answer is wrong to display the message “no, please try again” and...
Java Programming Use a one-dimensional array to solve the following program. Write an application that inputs six numbers [Keep the numbers in an array]. The numbers must be between 20 and 200, inclusive. If the number is not between 20 and 200, ask for another input. When a number is entered, display the number only if it is not a duplicate of a number already entered. If it is a duplicate of a number already entered, display a message that...
x= Suppose you are building a program for teaching kids' math. Write a java program the does the following: 1. Ask the user if he/she wants to sign-up a. If yes continue to step 2 b. If no Display the message "Thank you, Have a nice Day 2. Ask the user to enter a username. 3. Ask the user to enter a password with at least 8 characters long 4. Write a method with the following header: public static Boolean...
see below: You will be creating a personal quiz that will provide a grade depending on the responses given. The quiz should contain at least three questions of the true/false or multiple-choice nature. You should select only one type of question to use. These questions should originate from Comprehension Check in your textbook (noting the chapter and page number) These questions and the correct answer identifier should be stored in a text file. A second table should contain the possible...
I have to use java programs using netbeans. this course is introduction to java programming so i have to write it in a simple way using till chapter 6 (arrays) you can use (loops , methods , arrays) You will implement a menu-based system for Hangman Game. Hangman is a popular game that allows one player to choose a word and another player to guess it one letter at a time. Implement your system to perform the following tasks: Design...
Write a GUI-based Java application that implements the "Math Game" shown below. The program asks the user to enter the answer of multiplying two one-digit random integers. If the user enters a correct answer, a message will be displayed at the bottom of the frame, and the text field will be cleared. If the user enters a wrong answer, a message will be displayed at the bottom of the frame asking for another answer. If the user...
Programming language: JAVA Implement a superclass Appointment and subclasses OneTime, Daily, and Monthly. An appointment has a description (for example "see the dentist") and a date. Write a method OccursOn (int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, check whether the day of the month matches. Ask the user to enter a date to check (for example, 2006 10 5), and ask to user if they want...
*Java* Given the attached Question class and quiz text, write a driver program to input the questions from the text file, print each quiz question, input the character for the answer, and, after all questions, report the results. Write a Quiz class for the driver, with a main method. There should be a Scanner field for the input file, a field for the array of Questions (initialized to 100 possible questions), and an int field for the actual number of...
3. You are taking a multiple-choice quiz that consists of 6 questions. Each question has four possible answers, only one of which is correct. To complete the quiz, you randomly guess the answer to each question. a) Find the chance of guessing exactly three answers correctly b) Find the chance of guessing more than four answers correctly
Using Java develop a GUI based simple quiz game. The questions and answers of the game will be stored in a text file (i.e. our database). On the first page the users will be provided with some instructions on how to play the game and next button to go to the next page. On the next page will be a start button to either start the game and an exit button to exit the game. Once the game starts there...