Assignment #39 and A Little Quiz
Code
/// Name: Brendan Baird
/// Period: 6
/// Program Name: A Little Quiz
/// File Name: LittleQuiz.java
/// Date Finished: 10/5/2015
import java.util.Scanner;
public class LittleQuiz{
public static void main(String[] args){
Scanner keyboard = new Scanner(System.in);
String start;
int answer1, answer2, answer3, score;
score = 0;
System.out.print("Are you ready for a quiz? ");
start = keyboard.next();
System.out.println("Okay, here it comes!");
System.out.println();
System.out.println("Q1) What is the capital of England?");
System.out.println(" 1) Paris");
System.out.println(" 2) London");
System.out.println(" 3) Murica");
System.out.println();
answer1 = keyboard.nextInt();
if (answer1 == 2)
{
System.out.println("That's right!");
score ++;
}
else
{
System.out.println("Sorry, that's not correct.");
}
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.println();
answer2 = keyboard.nextInt();
if (answer2 == 2)
{
System.out.println("That's right!");
score ++;
}
else
{
System.out.println("Sorry, \"cat\" is a string. Ints can only store numbers.");
}
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");
answer3 = keyboard.nextInt();
if (answer3 == 2)
{
System.out.println("That's right!");
score ++;
}
else
{
System.out.println("Sorry, that's incorrect.");
}
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