Assignment #39 and A Little Quiz
Code
///Name: Tim Gibson
///Period: 6
///Project Name: A Little Quiz
///File Name: Quiz.java
///Date Finished: 10/5/15
import java.util.Scanner;
public class Quiz
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int a1, a2, a3, q1, q2, q3, total;
String ready;
System.out.print( "Are you ready for a quiz?" );
ready = keyboard.next();
System.out.println( "Okay, here it comes!" );
System.out.println( "\n1) What is the capital of Portugal?" );
System.out.println( "\t1. Paris \n\t2. Madrid \n\t3. Lisbon\n" );
a1 = keyboard.nextInt();
if ( a1 == 3 )
{
System.out.println( "That's correct!" );
q1 = 1;
}
else
{
System.out.println( "Sorry, the capital of Portugal is Lisbon." );
q1 = 0;
}
System.out.println( "\n2) Who was the American President during the Civil War?" );
System.out.println( "\t1. Grover Cleveland \n\t2. Abraham Lincoln \n\t3. Theodore Roosevelt\n" );
a2 = keyboard.nextInt();
if ( a2 == 2 )
{
System.out.println( "That's correct!" );
q2 = 1;
}
else
{
System.out.println( "Sorry, Abraham Lincoln was President during the Civil War." );
q2 = 0;
}
System.out.println( "\n3) Who won the 2014 World Cup?" );
System.out.println( "\t1. Germany \n\t2. USA \n\t3. Argentina\n" );
a3 = keyboard.nextInt();
if ( a3 == 1 )
{
System.out.println( "That's correct!" );
q3 = 1;
}
else
{
System.out.println( "Sorry, Germany won the 2014 World Cup." );
q3 = 0;
}
total = q1 + q2 + q3;
System.out.println( "\nOverall, you got " + total + " out of 3 correct." );
System.out.println( "Thanks for playing!" );
}
}
Picture of the output