jeudi 5 octobre 2017

How to keep track of answers on a multiple choice test in Java

I'm currently in an intro course on coding and my assignment is to code a multiple choice test of 7 questions with answers A,B,C,D. And at the end I have to see if someone had entered all C's, then I would have to print out a specific statement about that. How would I do that towards the end of my code using If Else statement? Thanks!

int score = 0;
Scanner kbd = new Scanner(System.in);

System.out.println("Entomology is the science that studies");
System.out.println("A. Behavior of human beings");
System.out.println("B. Insects");
System.out.println("C. The origin and history of technical and scientific terms");
System.out.println("D. The formation of rocks");
System.out.println("Please enter your answer: ");
char answer1 = kbd.next().charAt(0);
if (Character.toUpperCase(answer1) == 'B'){
    score++;
}

System.out.println("Eritrea, which became the 182nd member of the UN in 1993, is in the continent of");
System.out.println("A. Asia");
System.out.println("B. Africa");
System.out.println("C. Europe");
System.out.println("D. Australia");
char answer2 = kbd.next().charAt(0);
if (Character.toUpperCase(answer2) == 'B'){
    score++;
}

System.out.println("Which of the following is not one of the bots on Mystery Science Theater 3000?");
System.out.println("A. Jambot");
System.out.println("B. Gypsy");
System.out.println("C. Tom Servo");
System.out.println("D. Crow T.Robot");
char answer3 = kbd.next().charAt(0);
if (Character.toUpperCase(answer3) == 'A'){
    score++;
}

System.out.println("Germany signed the Armistice Treaty on ____ and World War I ended");
System.out.println("A. January 19, 1918");
System.out.println("B. May 30, 1918");
System.out.println("C. November 11, 1918");
System.out.println("D. February 15, 1918");
char answer4 = kbd.next().charAt(0);
if (Character.toUpperCase(answer4) == 'C'){
    score++;
}

System.out.println("The headquarters of the United Nations are situated at");
System.out.println("A. New York. USA");
System.out.println("B. Hague (Netherlands");
System.out.println("C. Geneva");
System.out.println("D. Paris");
char answer5 = kbd.next().charAt(0);
if (Character.toUpperCase(answer5) == 'A'){
    score++;
}

System.out.println("What utensil serves as the rallying cry of The Tick?");
System.out.println("A. chopstick");
System.out.println("B. spoon");
System.out.println("C. fork");
System.out.println("D. butter knife");
char answer6 = kbd.next().charAt(0);
if (Character.toUpperCase(answer6) == 'B'){
    score++;
}

System.out.println("What is the theme of the board game Die Macher?");
System.out.println("A. sculpting");
System.out.println("B. car racing");
System.out.println("C. German politics");
System.out.println("D. castle building");
char answer7 = kbd.next().charAt(0);

if (Character.toUpperCase(answer7) == 'C'){
    score++;
}

if (score >= 5){
    System.out.print("You  have passed the quiz!");
}
else{
    System.out.print("You have failed the quiz.");
}

Aucun commentaire:

Enregistrer un commentaire