Assignment #39

Code

    /// Gian Adoremos
    /// Period: 7
    /// Program Name: ThirtyNinth Program
    /// File Name: LittleQuiz.java
    /// Date Finished: 11/9/2015
   
   import java.util.Scanner;

    public class LittleQuiz{
    
        public static void main(String[] args){
        
            Scanner keyboard = new Scanner(System.in);
            
            String start;
            int answer1, answer2, answer3, score;
            score = 0;
            
            System.out.print("Are you ready for a quiz? ");
            start = keyboard.next();
            
            System.out.println("Okay, here it comes!");
            System.out.println();
            
            System.out.println("Q1) What is the capital of Guam?");
            System.out.println("        1) Dededo");
            System.out.println("        2) Yigo");
            System.out.println("        3) Agana");
            System.out.println();
            answer1 = keyboard.nextInt();
            
            if (answer1 == 3)
            {
                System.out.println("That's right!");
                score ++;
            }
            else
            {
                System.out.println("Sorry, that's not correct.");
            }
            
            System.out.println();
            System.out.println("Q2) Can you store the value \"cat\" in a variable of type int?");
            System.out.println("        1) yes");
            System.out.println("        2) no");
            System.out.println();
            answer2 = keyboard.nextInt();
            
            if (answer2 == 2)
            {
                System.out.println("That's right!");
                score ++;
            }
            else
            {
                System.out.println("Sorry, \"cat\" is a string. Ints can only store numbers.");
            }
            
            System.out.println();
            System.out.println("Q3) What is the result of 9+6/3?");
            System.out.println("        1) 5");
            System.out.println("        2) 11");
            System.out.println("        3) 15/3");
            answer3 = keyboard.nextInt();
            
            if (answer3 == 2)
            {
                System.out.println("That's right!");
                score ++;
            }
            else
            {
                System.out.println("Sorry, that's incorrect.");
            }
            
            System.out.println();
            System.out.println();
            System.out.println("Overall, you got " + score + " out of 3 correct.");
            System.out.println("Thanks for playing!");
        }
    }
 

Picture of the output

Assignment 39