Assignment #39 A Little Quiz
Code
/// Name: Koosha Kimelman
/// Period: 7
/// Program Name: A Little Quiz
/// File Name: LittleQuiz.java
/// Date Completed: 10/6/15
import java.util.Scanner;
public class LittleQuiz {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String answer;
int q1, q2, q3, score;
System.out.print("Are you ready for a quiz? (Y/N) ");
answer = keyboard.next();
if (answer.equals("Y")) {
System.out.println("Good! Here's question #1");
}
else if (answer.equals("N")) {
System.out.println("Well too bad because we're starting anyways!");
}
else {
System.out.println("You didn't answer either way you were supposed to. You're lucky this isn't one of the ones being graded. Here's the first question.");
}
System.out.println();
System.out.println("Question 1: What programming language was used to make this quiz?");
System.out.println(" 1. HTML");
System.out.println(" 2. Java");
System.out.println(" 3. Python");
System.out.println();
System.out.print("Answer? (1-3) > ");
q1 = keyboard.nextInt();
System.out.println();
if (q1 == 1 || q1 == 3) {
System.out.println("Sorry that's wrong, the correct answer was 2");
q1 = 0;
}
else if (q1 == 2) {
System.out.println("That's correct! Nice.");
q1 = 1;
}
else {
System.out.println("That wasn't any of the three answers. Sorry, that's wrong");
q1 = 0;
}
System.out.println();
System.out.println("Question 2: How many days in a fortnight?");
System.out.println(" 1. 1");
System.out.println(" 2. 14");
System.out.println(" 3. 7");
System.out.println(" 4. 20");
System.out.println(" 5. 4");
System.out.println();
System.out.print("Answer? (1-5) > ");
q2 = keyboard.nextInt();
System.out.println();
if (q2 == 1 || q2 == 3 || q2 == 4 || q2 == 5) {
System.out.println("Incorrect, the right answer was 2");
q2 = 0;
}
else if (q2 == 2) {
System.out.println("Nice job!");
q3 = 1;
}
else {
System.out.println("Not one of the possible answers. You got this one wrong");
q2 = 0;
}
System.out.println();
System.out.println("Question 3: How many lines of code are in this program?");
System.out.println(" 1. 137");
System.out.println(" 2. 87");
System.out.println(" 3. 126");
System.out.println(" 4. This question is unfair");
System.out.println();
System.out.print("Answer? (1-4) > ");
q3 = keyboard.nextInt();
System.out.println();
if (q3 == 2 || q3 == 3) {
System.out.println("You got it wrong, you should have gone with number 4 instead of guessing");
q3 = 0;
}
else if (q3 == 1) {
System.out.println("Wow, that was a good guess. Nice! Number 4 would also have been acceptable");
q3 = 1;
}
else if (q3 == 4) {
System.out.println("Yes. Yes it is an unfair question. I'll give that one to you, but 1 was the correct answer if you wanted to know");
q3 = 1;
}
else {
System.out.println("You didn't even choose one of the right answers. -1 for this question");
q3 = 0;
}
System.out.println();
System.out.println();
score = (q1 + q2 + q3);
System.out.println("Results: You got " + score + " out of 3 correct.");
if (score == 3) {
System.out.println("Nice job on getting them all right");
}
else if (score == 1 || score == 2) {
System.out.println("Nice try at least. You can't win them all");
}
else if (score == 0) {
System.out.println("Better luck next time maybe.");
}
System.out.println("Thanks for taking the quiz");
}
}
Picture of the output