Programming Assignment #35
Code
/// Name: Dylan Sleeper
/// Period: 6
/// Program Name: Else and If
/// File Name: Weekday.java
/// Date Finished: 10/22/2015
import java.util.Scanner;
public class Quiz{
public static void main(String[] args){
Scanner keyboard = new Scanner(System.in);
int score = 0;
int answer = 0;
System.out.print("Are you ready for a quiz? ");
keyboard.next();
System.out.println();
System.out.println("Q1) What is my name?");
System.out.println(" 1) Jack");
System.out.println(" 2) Bill");
System.out.println(" 3) Dylan");
answer = keyboard.nextInt();
if(answer == 3){
System.out.println("");
System.out.println("You got it right!");
score++;
}
else{
System.out.println("");
System.out.println("Nope, not quite.");
}
System.out.println();
System.out.println("Q2) How old is the earth?");
System.out.println(" 1) 1 year old");
System.out.println(" 2) 2 years old");
System.out.println(" 3) More than 2 years old");
answer = keyboard.nextInt();
if(answer == 3){
System.out.println("");
System.out.println("You got it right!");
score++;
}
else{
System.out.println("");
System.out.println("Nope, not quite.");
}
System.out.println();
System.out.println("Q3) Which of the following is a color?");
System.out.println(" 1) Apple");
System.out.println(" 2) Orange");
System.out.println(" 3) Pear");
answer = keyboard.nextInt();
if(answer == 2){
System.out.println("");
System.out.println("You got it right!");
score++;
}
else{
System.out.println("");
System.out.println("Nope, not quite.");
}
System.out.println("");
System.out.println("");
System.out.println("Overall you got " + score + " out of 3 correct");
System.out.println("Thanks for playing.");
}
}
Outputs