Assignment #39
Code
///jack newsom
///period 5
///program name LittleQuiz
///filename LittleQuiz.java
///date of completion 9/23/15
import java.util.Scanner;
public class LittleQuiz
{
public static void main( String[] args)
{
Scanner quizbot = new Scanner(System.in);
String johnCena;
int ansOne, ansTwo, ansThree, score = 0;
System.out.println("Are you ready for a quiz?");
johnCena = quizbot.next();
System.out.println("Ok, 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("");
ansOne = quizbot.nextInt();
if ( ansOne == 3 )
{
System.out.println("That's right.");
score = score + 1;
}
else
{
System.out.println("Sadly, " + ansOne + " isn't correct.");
}
System.out.println();
System.out.println("Q2) Can you store the value \"cat\" in a variable of type int?");
System.out.println("\t1) Yes");
System.out.println("\t2) No");
System.out.println();
ansTwo = quizbot.nextInt();
if ( ansTwo == 2 )
{
System.out.println("That's right!");
score = score + 1;
}
else
{
System.out.println("Sadly, " + ansTwo + " isn't correct.");
}
System.out.println();
System.out.println("Q3) What is the result of 9+6/3?");
System.out.println("\t1) 5");
System.out.println("\t2) 11");
System.out.println("\t3) 15/3");
System.out.println();
ansThree = quizbot.nextInt();
if ( ansThree == 2 )
{
System.out.println("That's correct!");
score = score + 1;
}
else
{
System.out.println("Sadly, " + ansThree + " isn't correct.");
}
System.out.println("Overall, you got " + score + " out of 3 correct.");
System.out.println("Thanks for playing!");
}
}
Picture of the output