Assignment #39 Little Quiz
Code
/// Name: John Huh
/// Period: 6
/// Program Name: A Little Quiz
/// File Name: LittleQuiz.java
/// Date Finished: 10/7/2015
import java.util.Scanner;
public class LittleQuiz
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int q1, q2, q3, score;
String ans;
score = 3;
System.out.print( "Are you ready for a quiz? " );
ans = keyboard.next();
System.out.print( "Okay, here it comes!" );
System.out.println();
System.out.println();
System.out.println( "Q1) What is the capital of Illinois?" );
System.out.println( " 1) Chicago" );
System.out.println( " 2) Springfield" );
System.out.println( " 3) Detroit" );
System.out.println();
System.out.print( "> " );
q1 = keyboard.nextInt();
System.out.println();
if ( q1 == 2 )
{
System.out.println( "That's right!" );
}
else
{
System.out.println( "That's wrong, Springfield is the capital of Illinois." );
}
System.out.println();
System.out.println( "Q2) What is my sixth period class?" );
System.out.println( " 1) Japanese" );
System.out.println( " 2) English" );
System.out.println( " 3) Computer Programming" );
System.out.println();
System.out.print( "> " );
q2 = keyboard.nextInt();
System.out.println();
if ( q2 == 3 )
{
System.out.println( "That's right!" );
}
else
{
System.out.println( "That's wrong, I have Computer Programming sixth period." );
}
System.out.println();
System.out.println( "Q3) What is 7+15/5?" );
System.out.println( " 1) 22/5" );
System.out.println( " 2) 10" );
System.out.println( " 3) 8/5" );
System.out.println();
System.out.print( "> " );
q3 = keyboard.nextInt();
System.out.println();
if ( q3 == 2 )
{
System.out.println( "That's correct!" );
}
else
{
System.out.println( "That's wrong, order of operations make it so 6/3 = 2 and 9+2 = 11." );
}
System.out.println();
System.out.println();
if ( q1 == 2 )
{
score = ( score+0 );
}
else
{
score = ( score-1 );
}
if ( q2 == 3 )
{
score = ( score+0 );
}
else
{
score = ( score-1 );
}
if ( q3 == 2 )
{
score = ( score+0 );
}
else
{
score = ( score-1 );
}
System.out.println( "Overall, you got " + score + " out of 3 correct." );
System.out.println( "Thanks for playing!" );
}
}
Picture of the output