Assignemnt #39 and A little quiz
Code
///name: Nick Cerdan
///period: 6
///Program name: A Little Quiz
///file name: Quiz.java
///date finished:
import java.util.Scanner;
public class Quiz
{
public static void main (String[] args)
{
Scanner keyboard = new Scanner(System.in);
int response, q1, q2, q3, cont;
cont = 0;
System.out.println("Are you ready for a quiz? (1 means yes, 2 means no)");
response = keyboard.nextInt();
if ( response == 1 )
{
System.out.println("OK! Here it is!");
}
else
{
System.out.println("Well too bad!");
}
System.out.println("");
System.out.println("Q1.) What is Nick's favorite color?");
System.out.println(" 1.) Green");
System.out.println(" 2.) Pink");
System.out.println(" 3.) Red");
System.out.println("");
System.out.print("Answer > ");
q1 = keyboard.nextInt();
System.out.println("");
if ( q1 == 1 )
{
System.out.println("Great job, you got it right!");
cont++;
}
else
{
System.out.println("Sorry, that is not Nick's favorite color");
}
System.out.println("");
System.out.println("Q2.) True of False: Mark is silly");
System.out.println(" 1.) True");
System.out.println(" 2.) False");
System.out.println("");
System.out.print("Answer > ");
q2 = keyboard.nextInt();
System.out.println("");
if ( q2 == 1 )
{
System.out.println("Great job, you got it right!");
cont++;
}
else
{
System.out.println("Sorry, you were wrong, Mark is silly");
}
System.out.println("");
System.out.println("Q3.) Where was Nick born?");
System.out.println(" 1.) Walnut creek");
System.out.println(" 2.) Jackson Hole");
System.out.println(" 3.) Fresno");
System.out.println("");
System.out.print("Answer > ");
q3 = keyboard.nextInt();
System.out.println("");
if ( q3 == 2 )
{
System.out.println("Great job, you got it right!");
cont++;
}
else
{
System.out.println("Sorry, you were wrong, Nick was born in Jackson Hole");
}
System.out.println("");
///This is where I attempt to keep track of it
if ( cont == 0 )
{
System.out.println("Uh Oh! You got " + cont + "/3 right! Better luck next time!");
}
else if ( cont == 1 )
{
System.out.println("You got " + cont + "/3 right.");
}
else if ( cont == 2 )
{
System.out.println("Good job, you got " + cont + "/3 right! That's pretty good!");
}
else
{
System.out.println("congratulations! You got " + cont + "/3 right! You got 100%!");
}
}
}