Assignemnt #39: A Little Quiz
Code
/// Name: Kelsey Lieberman
/// Period 5
/// Program Name: ALittleQuiz
/// File Name: ALittleQuiz.java
/// Date Finished: 10/21/2015
import java.util.Scanner;
public class ALittleQuiz
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
String ans1, ans2, ans3;
System.out.print("\nAre you ready for a quiz? ");
keyboard.next();
System.out.println("Okay, here you go!\n");
System.out.println("Q1) What is the answer to life, the universe, and everything?");
System.out.println("\ta) Dank Memes\n\tb) gravity\n\tc) 42\n");
System.out.print(">> ");
ans1 = keyboard.next();
if (ans1.equals("c"))
{ System.out.println("\nCorrect, glad you've read Hitchhikers Guide to the Galaxy.\n");}
else
{ System.out.println("\nSorry, that is incorrect.\n");}
System.out.println("Q2) What is my favorite color?");
System.out.println("\ta) red\n\tb) blue\n\tc) green\n");
System.out.print(">> ");
ans2 = keyboard.next();
if (ans2.equals("a"))
{ System.out.println("\nCorrect.\n");}
else
{ System.out.println("\nSorry, that is incorrect.\n");}
System.out.println("Q3) What is Rick's catch phrase?");
System.out.println("\ta) wubba lubba dub dub\n\tb) ooga booga og nog\n\tc) waka schlaka bawk bawk\n");
System.out.print(">> ");
ans3 = keyboard.next();
if (ans3.equals("a"))
{ System.out.println("\nCorrect. Wubba lubba dub dub!\n");}
else
{ System.out.println("\nSorry, that is incorrect.\n");}
if (ans1.equals("c") && ans2.equals("a") && ans3.equals("a"))
{ System.out.println("Overall Score: 3/3 answers correct");}
else if (ans1.equals("c") && ans2.equals("a")&& !ans3.equals("a"))
{ System.out.println("Overall Score: 2/3 answers correct");}
else if (ans1.equals("c") && ! ans2.equals("a") && ans3.equals("a"))
{ System.out.println("Overall Score: 2/3 answers correct");}
else if (! ans1.equals("c") && ans2.equals("a") && ans3.equals("a"))
{ System.out.println("Overall Score: 2/3 answers correct");}
else if (! ans1.equals("c") && !ans2.equals("a") && ans3.equals("a"))
{ System.out.println("Overall Score: 1/3 answers correct");}
else if (! ans1.equals("c") && ans2.equals("a") && !ans3.equals("a"))
{ System.out.println("Overall Score: 1/3 answers correct");}
else if (ans1.equals("c") && !ans2.equals("a") && !ans3.equals("a"))
{ System.out.println("Overall Score: 1/3 answers correct");}
else if (! ans1.equals("c") && !ans2.equals("a") && !ans3.equals("a"))
{ System.out.println("Overall Score: 0/3 answers correct");}
else
{ System.out.println("Please enter valid answers:a, b, or c");}
System.out.println("Thanks for playing!");
}
}
Picture of the output