Create A Quiz Program In Java

  1. Create A Quiz Program In Java
  2. How To Program In Java
  3. Create A Quiz Program In Javascript

Create a class Book with the following private member variables. Include appropriate getters and setters method. Create a class TestBook which has the main method. Get the details as shown in the sample input. Create an object for book class and assign the value for its attrbutes using the setters. Now your tests just print a '.' If they work, but give you a neat report if they fail. One note, see how I had to turn the double result into a string with '+method. That's a little kludgey and a bit hard to predict. You might prefer another assertEquals method that takes two doubles as arguments.

A simple way you can achieve this would be to have a while-loop inside the main loop of your quiz code which checks your input variable value.


You would set the initial value of the variable that holds the value of the users input to a default string and check to make sure that you keep asking the user for an input while the value of that input is not equal to your desired inputs of: ['D', 'C', 'B', 'A']


You can achieve this using the logical '&&' (and) operator to check and make sure that if the input is not equal to any of the acceptable input you continue looping for an input. This way each time the user inputs a value, the program does not move on until it sees a recognized input.

How


Specifically in pseudo-code you would write this:


do {


user_ans[i] = ';


do {

user_ans[i] = USER_INPUT

} while(user_ans[i] != 'D' && user_ans[i] != 'C' && user_ans[i] != 'B' && user_ans[i] != 'A');


continue_main_loop_logic();

Create A Quiz Program In Java


How To Program In Java

} while ()

Anonymous A.

Create A Quiz Program In Javascript

where to put this piece of code? I have tried but the code stops after printing 1st question. import java.io.*; import java.util.*; import java.util.Scanner; public class Main { static Scanner cin = new Scanner(System.in); public static void main(String[] args) { int correct = 0; int incorrect = 0; int questions = 5; System.out.println('Welcome to the Multiple Choice Quiz! n'); String[][] Ques_Ans = { { 'What is the size of float variable? ', 'n A. 8 bit n B. 16 bit n C. 32 bit n D. 64n', 'C' }, { 'Which one of these is not a primitive data type? ', 'n A. integer n B. char n C. float n D. doublen', 'B' }, { 'Which data type is used to create a variable that should store text? ', 'n A. myString n B. string n C. character n D. String64n', 'D' }, { 'How do you create a variable with the numeric value 5? ', 'n A. num x = 5; n B. float x = 5; n C. x = 5; n D. int x = 5;n', 'A' }, { 'Which method can be used to find the length of a string in JAVA?', 'n A. length() n B. getlength() n C. len n D. getsize()n', 'A' } }; String[] user_ans = new String[(int) questions]; int i = 0; String USER = '; do { System.out.print(' + (i + 1) + '. ' + Ques_Ans[i][0] + ' ' + Ques_Ans[i][1]); user_ans[i] = String.valueOf(cin.next().charAt(0)); user_ans[i] = '; do { user_ans[i] = USER; } while (user_ans[i] != 'D' user_ans[i] != 'C' user_ans[i] != 'B' user_ans[i] != 'A'); if (Ques_Ans[i][2].equals(user_ans[i])) { System.out.println('n Correct!'); correct++; } else { System.out.println('n Incorrect. The correct answer is ' + Ques_Ans[i][2]); incorrect++; } System.out.print('n'); i++; } while (i < questions); System.out.println('n Number of correct answers: ' + correct); System.out.println('n Number of incorrect answers: ' + incorrect); System.exit(0); } }