Assignment #39 and LittleQuiz
Code
/// Name: Jason Kim
/// Period: 7
/// Program Name: LittleQuiz
/// File Name: LittleQuiz.java
/// Date Finished:10/7/15
import java.util.Scanner;
public class LittleQuiz
{
public static void main (String [] args)
{
Scanner keyboard = new Scanner(System.in);
int Q1, Q2, Q3, count = 0;
System.out.print("Are you ready for a quiz? ");
keyboard.next();
System.out.println("Okay, here it comes!");
System.out.println();
System.out.println("Q1) What is the capital of Alaska?");
System.out.println("\t1) Melbourne");
System.out.println("\t2) Anchorage");
System.out.println("\t3) Juneau");
System.out.println();
System.out.print("> ");
Q1 = keyboard.nextInt();
System.out.println();
if (Q1 == 3)
{
count +=1;
System.out.println("That's right!");
}
else
{
System.out.println("Sorry, the capital of Alaska is Juneau.");
}
System.out.println();
System.out.println("Q2) Can you store the value \"cat\" in a variable of type int?");
System.out.println("\t 1) yes");
System.out.println("\t 2) no:");
System.out.println();
System.out.print("> ");
Q2 = keyboard.nextInt();
System.out.println();
if (Q2 == 2)
{
count +=1;
System.out.println("That's right!");
}
else
{
System.out.println("Sorry, \"cat\" is a sting. ints can only store numbers.");
}
System.out.println();
System.out.println("Q3) What is the result of 9+6/3?");
System.out.println("\t 1) 5");
System.out.println("\t 2) 11");
System.out.println("\t 3) 15/3");
System.out.println();
System.out.print("> ");
Q3 = keyboard.nextInt();
System.out.println();
if(Q3 == 2)
{
count +=1;
System.out.println("That's correct!");
}
else
{
System.out.println("Sorry, 9+6/3 is 11");
}
System.out.println("\n\nOverall, you got " + count + " out of 3 correct.");
System.out.println("Thanks for playing!");
}
}
Picture of the output