Code
/// Name: Afaf Nabeeha
/// Period: 7
/// Program Name: Little Quiz
/// File Name: Quiz.java
/// Date Finished: 11/2/2015 public class Space
import java.util.Scanner;
public class Quiz
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
System.out.print( "Are you ready for a quiz? " );
keyboard.next();
System.out.println( "Okay here it comes! " );
System.out.println();
int answer1, answer2, answer3, a,b,c;
System.out.println( "Q1) What is the capital of Alaska? " );
System.out.println( " 1) Melbourne " );
System.out.println( " 2) Anchorage " );
System.out.println( " 3) Juneau " );
System.out.print("> " );
answer1 = keyboard.nextInt();
if ( answer1 == 3 )
{
System.out.println( "That's right! " );
a = 1;
}
else
{
System.out.println( "Sorry, Juneau is the capital. " );
a = 0;
}
System.out.println();
System.out.println( "Q2) Can you store the value \"cat\" in a variable of type int? " );
System.out.println( " 1) yes" );
System.out.println( " 2) no" );
System.out.print( "> " );
answer2 = keyboard.nextInt();
if ( answer2 == 2 )
{
System.out.println( "That's right! " );
b = a + 1;
}
else
{
System.out.println( " Sorry, \"cat\" is a string. ints can only store numbers. " );
b = a + 0;
}
System.out.println();
System.out.println( "Q3) What is the result of 9+6/3? " );
System.out.println( " 1) 5" );
System.out.println( " 2) 11" );
System.out.println( " 3) 15/3" );
System.out.print( "> " );
answer3 = keyboard.nextInt();
if ( answer3 == 2 )
{
System.out.println( "That's right! " );
c = b + 1;
}
else
{
System.out.println( "Sorry the answer is 11. " );
c = b + 0;
}
System.out.println();
System.out.println();
System.out.println( "Over all, you got " + c + " out of 3 correct. " );
System.out.println( "Thanks for playing." );
}
}
Picture of the output