Assignment #39

Code

///Name: Mahima Choudhary
///Period: 6
///Project Name: LittleQuiz
///File Name: LittleQuiz.java
///Date Finished: 10/27/15
    
    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 India?");
            System.out.println("        1) Nepal");
            System.out.println("        2) New Delhi'");
            System.out.println("        3) Miley Cyrus");
            System.out.println();
            answer1 = keyboard.nextInt();
            
            if (answer1 == 1)
            {
                System.out.println("That's right!");
                score ++;
            }
            else
            {
                System.out.println("Sorry, New Delhi is the capital of India.");
            }
            
            System.out.println();
            System.out.println("Q2) Should teenagers sleep for 9 or more hours?");
            System.out.println("        1) yes");
            System.out.println("        2) no");
            System.out.println();
            answer2 = keyboard.nextInt();
            
            if (answer2 == 1)
            {
                System.out.println("That's right!");
                score ++;
            }
            else
            {
                System.out.println("Sorry,teenagres need 9 or more hours to function and regenerate themselves.");
            }
            
            System.out.println();
            System.out.println("Q3) What is the result of 2+2?");
            System.out.println("        1) 5");
            System.out.println("        2) 4");
            System.out.println("        3) 3");
            answer3 = keyboard.nextInt();
            
            if (answer3 == 2)
            {
                System.out.println("That's right!");
                score ++;
            }
            else
            {
                System.out.println("Sorry, 2 plus 2 is 4.");
            }
            
            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

YourInitials.html