Assignemnt #39 A Little Quiz
Code
Name: Iaroslav Titov
Period: 7
Project Name: LittleQuiz
File Name: LittleQuiz.java
Date: 10/2/2015
import java.util.Scanner;
import java.util.InputMismatchException;
public class LittleQuiz
{
public static void main (String[] args)
{
Scanner keyboard = new Scanner(System.in);
boolean ready = false;
boolean[] results = {false,false, false};
String[] questions = {"What is the derivative of x^3+6x^2+98 ?","What is the periodic number of Hydrogen ? ", "What is 2+2 ? " };
String[][] answerChoice = {{"3x^2+12x","x^2+12","3x^2+12"},{"16","1","32"},{"5","4.000001","4"}};
int[] answers = {0,1,2};
try
{
System.out.print("Welcome to THE QUIZ!!! Are you ready? Y/N ");
if (keyboard.next().equals("Y")) ready = true;
if (ready)
{
for (int i = 0; i < 3;i++)
{
System.out.println();
System.out.println(questions[i]);
System.out.println();
for (int j = 0; j < 3;j++)
{
System.out.println(" "+(j+1)+") "+answerChoice[i][j]);
}
System.out.println();
System.out.print("Enter the number of your answer: ");
if (keyboard.nextInt()-1 == answers[i]) results[i] = true;
System.out.println();
if (results[i]) System.out.println("Good job!!!");
else System.out.println("You are wrong :( The answer is "+answerChoice[i][answers[i]]);
}
int finalResult = 0;
for (int i = 0; i < 3;i++) if (results[i]) finalResult++;
String response = "";
switch (finalResult)
{
case 3: response = "you are a genius!!!";
break;
case 2: response = "you are not bad.";
break;
case 1: response = "you are quite stupid.";
break;
case 0: response = "you are totally dumb!!!";
break;
}
System.out.println();
System.out.println("Your result is "+finalResult+" out of 3, therefore "+response);
}
else
{
System.out.println();
System.out.println("Goodbye then!!!");
}
}
catch (InputMismatchException e)
{
System.out.println( "WRONG INPUT!!!" );
}
}
}
Picture of the output