Assignment #39 and A Little Quiz
Code
/// Name: Lauren Baird
/// Period: 7
/// Program Name: A Little Quiz
/// File Name: ALittleQuiz.java
/// Date Finished: 10/13/2015
import java.util.Scanner;
public class ALittleQuiz
{
public static void main( String [] args )
{
Scanner keyboard = new Scanner(System.in);
String start;
int score, first, second, third;
score = 0;
System.out.print( "Are you ready for a quiz? " );
start = keyboard.next();
System.out.println( "Here it is!" );
System.out.println( "1) What is 8+4-3/3? " );
System.out.println( " 1. 2 " );
System.out.println( " 2. 3 " );
System.out.println( " 3. 5 " );
first = keyboard.nextInt();
if ( first == 1 )
{
System.out.println( "That's incorrect." );
}
else if ( first == 2 )
{
System.out.println( "That's right! " );
score ++;
}
else if ( first == 3 )
{
System.out.println( "Nope, that's incorrect. " );
}
else
{
System.out.println( "You didn't chose an answer that was provided." );
}
System.out.println();
System.out.println( "2) What is the capital of France? " );
System.out.println( " 1. Paris " );
System.out.println( " 2. London " );
second = keyboard.nextInt();
if ( second == 1 )
{
System.out.println( "Correct!" );
score ++;
}
else if ( second == 2 )
{
System.out.println( "Sorry, that's incorrect." );
}
else
{
System.out.println( "That answer was not a choice." );
}
System.out.println();
System.out.println( "3) Which of these can you put the value of '.08' in? " );
System.out.println( " 1. string " );
System.out.println( " 2. int " );
System.out.println( " 3. double " );
third = keyboard.nextInt();
if ( third == 1 )
{
System.out.println( "That's incorrect, 'string' cannot hold numbers." );
}
else if ( third == 2 )
{
System.out.println( "That's incorrect. 'int' can hold numbers, but it can't hold numbers that contain a decimal. ");
}
else if ( third == 3 )
{
System.out.println( "Correct!" );
score ++;
}
else
{
System.out.println( "You did not chose an answer that was provided." );
}
System.out.println();
System.out.println();
System.out.println( "Overall, you got " + score + " out of 3 correct. " );
System.out.println( "Thanks for playing!" );
}
}
Picture of the output