Prog39: A Little Quiz
///Name: Ilana Levy
///Period: 5
///Project Name: A Little Quiz
///File Name: littleQuiz.java
///Date Finished:9/9/2015
import java.util.Scanner;
public class littleQuiz
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner( System.in );
String firstQ;
int Q1, Q2, Q3, total=0;
System.out.print( "Are you ready for a quiz? " );
firstQ = keyboard.next();
System.out.println( "Q1) What is the capital of Alaska? \n\t\t 1) Melbourne\n\t\t 2) Anchorage\n\t\t 3) Juneau " );
Q1 = keyboard.nextInt();
if ( Q1 == 3 )
{
System.out.println( "That's right!" );
}
System.out.println( "Q2) Can you store teh value \"cat\" in a variable of type int?\n\t\t 1) yes\n\t\t 2) no " );
Q2 = keyboard.nextInt();
if ( Q2 == 2 )
{
System.out.println(" That's right!" );
}
else
{
System.out.println( "Sorry, \"cat\" is a string. ints can only store numbers." );
}
System.out.println( "Q3) What is the result of 9+6/3? \n\t\t 1) 5\n\t\t 2) 11\n\t\t 3) 15/3 " );
Q3 = keyboard.nextInt();
if ( Q3 == 2 )
{
System.out.println(" That's right!" );
}
else
{
System.out.println(" That's wrong!" );
}
if ( Q1 == 3 && Q2 == 2 && Q3 == 2 )
{
total = 3;
}
else if ( Q1 != 3 && Q2 == 2 && Q3 == 2 )
{
total = 2;
}
else if ( Q1 == 3 && Q2 != 2 && Q3 == 2 )
{
total = 2;
}
else if ( Q1 == 3 && Q2 == 2 && Q3 != 2 )
{
total = 2;
}
else if ( Q1 != 3 && Q2 != 2 && Q3 == 2 )
{
total = 1;
}
else if ( Q1 != 3 && Q2 == 2 && Q3 != 2 )
{
total = 1;
}
else if ( Q1 == 3 && Q2 != 2 && Q3 != 2 )
{
total = 1;
}
else if ( Q1 != 3 && Q2 != 2 && Q3 != 2 )
{
total = 0;
}
System.out.print( "Overall, you got " + total + " out of 3 correct. \n Thanks for playing!" );
}
}