Assignemnt #39 Quiz

Code

    ///Name: Joshua Pell
    ///Period: 6
    ///Project Name: Quiz
    ///File Name: Quiz.java
    ///Date: 10/23/2015
    
  import java.util.Scanner;
    
    public class Quiz
    {
        public static void main(String [] args)
        { 
                  
            Scanner keyboard = new Scanner(System.in);
            
            int ans1, ans2, ans3, score;
            score = 0;

            System.out.println("Here's a quiz.");
            System.out.println("What is the capital of Alaska?");
            System.out.println("         1)Melbourne          ");
            System.out.println("         2)Anchorage          ");
            System.out.println("         3)Juneau             ");
            ans1 = keyboard.nextInt();
            
            if (ans1 == 3)
            {
                System.out.println("That's correct!");
                score = score+1;
            }
            else
            {
                System.out.println("That's incorrect");
            }

            System.out.println("Can you store the value cat in a variable of type int?");
            System.out.println("        1)Yes                                         ");
            System.out.println("        2)No                                          ");
            ans2 = keyboard.nextInt();
    
            if (ans2 == 2)
            {
                System.out.println("That's correct");
                score= score+1;
            }
            else
            {
                System.out.println("That's incorrect");
            }
            
            System.out.println("What is the result of 9+6/3?");
            System.out.println("      1)5                   ");
            System.out.println("      2)11                  ");
            System.out.println("      3)15/3                ");
            ans3 = keyboard.nextInt();
            
            if (ans3 == 2)
            {
                System.out.println("That's correct");
                score = score+1;
            }
            
            System.out.println("Overall, you got " + score + " out of 3 correct.");
            System.out.println("Thanks for playing");
    }
}
    

Picture of the output

Assignment 39