Assignment #39 and A Little Quiz
Code
/// Name: Ali Kurland
/// Period: 6
/// Program Name: A Little Quiz
/// File Name: ALittleQuiz.java
/// Date Finished: 9/28/2015
import java.util.Scanner;
public class ALittleQuiz
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
String answer1;
int answer2, answer3, answer4;
int score1, score2, score3;
System.out.print( "Are you ready for a quiz? " );
answer1 = keyboard.next();
System.out.println( "Okay, here it comes!" );
System.out.println( " " );
System.out.println( "Q1) What is the capital of California?" );
System.out.println( "\t 1) San Francisco" );
System.out.println( "\t 2) Sacramento" );
System.out.println( "\t 3) Los Angeles" );
System.out.println( " " );
System.out.print( "> " );
answer2 = keyboard.nextInt();
System.out.println( " " );
if ( answer2 == 2 )
{
System.out.println( "Good Job!" );
score1 = 1;
}
else
{
System.out.println( "Sorry, that is incorrect. The capital of California is Sacramento." );
score1 = 0;
}
System.out.println( " " );
System.out.println( "Q2) Can the value 2 be stored in a String?" );
System.out.println( "\t 1) yes" );
System.out.println( "\t 2) no" );
System.out.println( " " );
System.out.print( "> " );
answer3 = keyboard.nextInt();
System.out.println( " " );
if ( answer3 == 2 )
{
System.out.println( "Correct!" );
score2 = 1;
}
else
{
System.out.println( "Sorry, that is incorrect. Only words can be stored in Strings." );
score2 = 0;
}
System.out.println( " " );
System.out.println( "Q3) What is 5 * 10?" );
System.out.println( "\t 1) 50" );
System.out.println( "\t 2) 15" );
System.out.println( "\t 3) 5" );
System.out.println( " " );
System.out.print( "> " );
answer4 = keyboard.nextInt();
System.out.println( " " );
if ( answer4 == 1 )
{
System.out.println( "Correct!" );
score3 = 1;
}
else
{
System.out.println( "Sorry, that is incorrect. 5 * 10 is 50." );
score3 = 0;
}
System.out.println( " " );
System.out.println( "Overall, you got " + ( score1 + score2 + score3 ) + " out of 3 correct." );
System.out.println( "Thanks for playing!" );
}
}
Picture of the output