/**
* Created By: Qamar
* This program creates a quiz out of 30 questions and
* randomly selects 25 questions and then tells you your answer.
* Created: April 17 2008
*/
import javax.swing.*;// imports the superclass that allows for use of GUI
import java.util.Random; // imports the random class
public class Java_Quiz { //
public static void main(String[] args) {//
String[] Qs = {"What does OOP stand for?", "Which line of code prints out words?", "How do you comment a line in Java?", "Which line converts the string input into a float?", "How do you make an integer?", "What does ??args?? stand for?", "What kind of programming language does Java use?", "How would you print ??Hello?? on the screen?", "How does Bluej accept the value ??x1?? as an integer?", "What does FLOAT do (when insterted into the program properly)?", "What does % do?", "How would you square root x1?", "How do you print on a line?", "How do you make the program accept the name?", "What do you put at the end of a piece of code?", "What can a string do?", "What is missing with this line of code?: ??num = 5(4);??", "What do you start a string or class with?", "What does commenting do?", "What is the proper term to randomize?", "How does ?while? work, when inserted into the code correctly?", "What should go at the top of your program?", "How do you import all of the Java classes?", "Java programming language can run on any platform because...", "What is the purpose of the main method?", "What does ?System.out.print? do?", "When trying to add marks in a multiple choice quiz, what statement would work?", "A class cannot be declared...", "Following code will result in: class A { int b = 1; public static void main(String [] args) { System.out.println(?b is ? + b); }}", "Following code will result in: int a1 = 5; double a2 = (float)a1; ..."};
String[] As = {"1) Official Or Protocol", "1) Print.String.", "1) //", "1) num = Float.parse (reader.readLine())", "1) int num1;", "1) an onomatopoeia", "1) Object-Orientated", "1) put ??Hello??", "1) get x1;", "1) it makes it possible to have a decimal value with a whole number", "1) divides a number", "1) SquareRoot(x1):", "1) System.out.print(line)", "1) name = (reader.readLine());", "1) /", "1) can hold numbers (it?s numerical value) and words", "1) +", "1) {", "1) changes an integer into a double", "1) randomize", "1) while works like an ??if?? and a loop", "1) your name", "1) import java.io.*;", "1) Java is written in C++", "1) To build a user interface", "1) lets you write something while the program is running", "1) while", "1) Static", "1) Complication error", "1) Compilation error"};
String[] Bs = {"2) Object Oriented Programming", "2) System.out.println", "2) %", "2) num = float.parse (reader.readLine())", "2) make an int num1;", "2) an argument", "2) Array", "2) put (??Hello??)", "2) accept x1;", "2) it makes the program lighter", "2) multiplies a number", "2) Math.sqrt(x1);", "2) System.out.println", "2) name = (reader.readline());", "2) :", "2) can only hold numbers", "2) /", "2) (", "2) allows others to rate your coding skills", "2) randint", "2) while works like a loop", "2) the date", "2) JavaImportAll;", "2) The Java Virtual Machine1(JVM) interprets the program for the native operating system", "2) To create buttons and scrollbars", "2) lets you write something before you run the program", "2) if", "2) Private", "2) Runtime exception", "2) Runtime error"};
String[] Cs = {"3) Ontario Organized Police", "3) system.out.println", "3) \\", "3) num = Float.parseFloat(reader.readLine())", "3) integer num1;", "3) it stands for nothing", "3) Logic", "3) System.out.print(??Hello??);", "3) x1 = Integer.parseInt(reader.readLine());", "3) it acts the same way as integer, there?s no real difference", "3) divides a number and shows the remainder", "3) Squareroot(x1);", "3) System.out.printline", "3) name = (reader.readLine()):", "3) ;", "3) can only hold words", "3) *", "3) <", "3) makes it easier for others to understand the code", "3) randit", "3) while works like an ?if?", "3) a description of the program", "3) ClassimportJava;", "3) The compiler is the same as a C++ compiler", "3) To state that the name of the method", "3) prints your program (without prompting)", "3) ==", "3) Default", "3) Runtime error", "3) No errors"};
String[] Ds = {"4) Objective Oval Packets", "4) print.code", "4) ?", "4) num = floatparsefloat(reader.readLine())", "4) int num1:", "4) both A and B", "4) Functional", "4) System.out.print(??Hello??):", "4) x1 = parseInt(reader.readLine());", "4) it makes a whole value into a decimal", "4) shows the percentage of power being taken up during processing", "4) Math.sqrt(x1):", "4) System.out.printonaline", "4) name = (reader.readname());", "4) code end", "4) can hold numbers and words (but doesn?t hold the number?s numerical value)", "4) none of the above", "4) ?? ??", "4) doesn't make a difference", "4) random", "4) it allows the program to multi-task (ex. program calculates an answer WHILE it accepts another value)", "4) all of the above", "4) Java.io ImportClass", "4) Java is special", "4) To act as the entry point for the program", "4) shows your program and prompts the user to print", "4) &&", "4) Open", "4) Output of b = 1", "4) None of the above"};
int [] answer = {3,2,1,3,1,2,1,3,3,1,3,2,2,1,3,4,3,1,3,2,1,4,1,2,4,2,2,2,1,3}; // answer key
int retry = 0;
String retryy ;
while (retry < 2) { // retry loop
JOptionPane.showMessageDialog(null,"Welcome to Qamar's Java Quiz \n"
+ "You will shortly be asked 10 questions\n"
+ "Please enter a value between 1 - 4 for your answer\n"
+ "After you finish the quiz you will be presented with your final score");
int count = 0;
String ans;
float mark = 0;
float percent = 0;
int ans2 ;
int [] flag = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
while (count < 10) { // question loop
Random r = new Random();
int randint = r.nextInt(29); // array starts at 0 -> 29 which = 30
while (flag [randint] >= 1)
{
randint = r.nextInt(29);
flag [randint] = flag [randint];
}
ans = JOptionPane.showInputDialog("" + Qs[randint] + "\n"
+"" + As[randint] + "\n"
+"" + Bs[randint] + "\n"
+"" + Cs[randint] + "\n"
+"" + Ds[randint] + "\n" );
ans2 = Integer.parseInt(ans);
if (ans2 == answer[randint])
{
mark = mark+ 1;
}
flag [randint] = flag [randint] + 1;
count = count + 1;
} // end loop
percent = mark / count;
percent = percent * 100;
percent = Math.round (percent);
JOptionPane.showMessageDialog(null,"Your score is: " + mark + " out of " + count + " which is " + percent + "%");// diplays a pop-up that has the final information
retryy = JOptionPane.showInputDialog("Would you like to play again? \n"
+ "1) Yes\n"
+ "2) No");
retry = Integer.parseInt(retryy);
// if (retry == 1)
//
// {
// JOptionPane.showMessageDialog(null,"Okay here we go again. ");
// }
if (retry == 2)
{
JOptionPane.showMessageDialog(null,"Thank you for playing. ");
}
}// end retry loop
} // end method
} // end class |