Assignemnt #39 A Little Quiz
Code
/// Name: Jake Johnson
/// Period: 7
/// Program Name: A Little Quiz
/// File Name: ALittleQuiz.java
/// Date Finished: 10/7/2015
import java.util.Scanner;
public class ALittleQuiz
{
public static void main (String[] args)
{
String answer;
int score;
score = 0;
Scanner keyboard = new Scanner(System.in);
System.out.println("Welcome to my quiz! Lets get started.");
System.out.println();
System.out.println("1) What is type of variable that can hold words?");
System.out.println(" a) Int");
System.out.println(" b) String");
System.out.println(" c) Double");
System.out.println(" d) Bool");
System.out.println();
answer = keyboard.next();
system.out.println();
if (answer.equals("a"))
{
System.out.println("No, ints can only store integers");
score = 0;
}
else if (answer.equals("b"))
{
System.out.println("Good job! That's right.");
score = 1;
}
else if (answer.equals("c"))
{
System.out.println("No, doubles can only store numbers and decimals");
score = 0;
}
else if (answer.equals("d"))
{
System.out.println("No, booleans can only store true or false values");
score = 0;
}
System.out.println();
System.out.println("2) What is my (preferred) first name?");
System.out.println(" a) Jack");
System.out.println(" b) Jacob");
System.out.println(" c) Jake");
System.out.println(" d) Jakers");
System.out.println();
answer = keyboard.next();
system.out.println();
if (answer.equals("a"))
{
System.out.println("Not even close");
score = score + 0;
}
else if (answer.equals("b"))
{
System.out.println("My real first name, I prefer Jake though.");
score = score + 0;
}
else if (answer.equals("c"))
{
System.out.println("Correct!");
score = score + 1;
}
else if (answer.equals("d"))
{
System.out.println("Mom?");
score = score + 0;
}
System.out.println();
System.out.println("3) How many middle names do I have?");
System.out.println(" a) One");
System.out.println(" b) Two");
System.out.println(" c) Three");
System.out.println();
answer = keyboard.next();
system.out.println();
if (answer.equals("a"))
{
System.out.println("I wish");
score = score + 0;
}
else if (answer.equals("b"))
{
System.out.println("I wish");
score = score + 0;
}
else if (answer.equals("c"))
{
System.out.println("Sadly, yes.");
score = score + 1;
}
if (score == 3)
{
System.out.println("Good job! You got 3/3 correct!");
}
else if (score == 2)
{
System.out.println("Nice try! You got 2/3 correct!");
}
else if (score == 1)
{
System.out.println("Good effort! You got 1/3 correct.");
}
if (score == 0)
{
System.out.println("You failed! You got 0/3 correct.");
}
System.out.println("Thanks for playing!");
}
}
Picture of the output