I asked this question before, but I think that because i only included as piece of the code it was unclear. I am writing a program that asks the user what kind of question they want asked, and then they are prompted for an answer to that question. However, even the correct input from the user results in a return of an incorrect answer. Here's the code:
import java.util.Scanner;
public class MascotQuiz {
public static void main(String[] args) {
int score = 0;
String greeting = "In this game, I ask you four questions about mascots for "
+ "US collegiate sports teams."
+ "\nYou get 1 point for each correct answer, "
+ "0 points if you type don't know, "
+ "and you lose a point for wrong answers.";
final String schoolOptions = "University of Michigan, "
+ "University of Nebraska, " + "University of Oklahoma, "
+ "University of Wisconsin";
final String mascotOptions = "Badgers, Cornhuskers, Sooners, Wolverines";
String prompt1 = "\nType 1 and I'll give you the mascot and "
+ "you give give the school. \n"
+ "Type 2 and I'll give you the school and "
+ "you give me the mascot. \n" + "Type 3 and I'll quit.";
System.out.println(greeting);
int questionCount = 1;
String mascotQuestion1, mascotQuestion2, mascotQuestion3, mascotQuestion4;
String schoolQuestion1, schoolQuestion2, schoolQuestion3, schoolQuestion4;
do {
System.out.println(prompt1);
int optionChoice;
Scanner scan = new Scanner(System.in);
optionChoice = scan.nextInt();
if (optionChoice == 1) {
if (questionCount == 1) {
System.out.println("What school do the Badgers belong to?");
mascotQuestion1 = scan.nextLine();
if (mascotQuestion1.equalsIgnoreCase("University of Michigan")) {
score++;
}
else if (mascotQuestion1.equalsIgnoreCase("don't know")) {
score = (score + 0);
}
else {
score--;
}
}
else if (questionCount == 2) {
System.out.println("What school do the Cornhuskers belong to?");
mascotQuestion2 = scan.next();
if (mascotQuestion2.equalsIgnoreCase("University of Nebrasksa")) {
score++;
}
else if (mascotQuestion2.equalsIgnoreCase("don't know")) {
score = (score + 0);
}
else {
score--;
}
}
else if (questionCount == 3) {
System.out.println("What school do the Sooners belong to?");
mascotQuestion3 = scan.next();
if (mascotQuestion3.equalsIgnoreCase("University of Oklahoma")) {
score++;
}
else if (mascotQuestion3.equalsIgnoreCase("don't know")) {
score = (score + 0);
}
else {
score--;
}
}
else {
System.out.println("What school do the Wolverines belong to?");
mascotQuestion4 = scan.next();
if (mascotQuestion4.equalsIgnoreCase("University of Winsconsin")) {
score++;
}
else if (mascotQuestion4.equalsIgnoreCase("don't know")) {
score = (score + 0);
}
else {
score--;
}
}
}
else if (optionChoice == 2) {
if (questionCount == 1) {
System.out.println("What mascot belongs to the University of Michigan?");
schoolQuestion1 = scan.next();
if (schoolQuestion1.equalsIgnoreCase("Badgers")){
score++;
}
else if (schoolQuestion1.equalsIgnoreCase("don't know")){
score = score + 0;
}
else {
score --;
}
}
else if (questionCount == 2) {
System.out.println("What mascot belongs to the University of Nebraska?");
schoolQuestion2 = scan.next();
if (schoolQuestion2.equalsIgnoreCase("Cornhuskers")){
score++;
}
else if (schoolQuestion2.equalsIgnoreCase("don't know")){
score = score + 0;
}
else {
score --;
}
}
else if (questionCount == 3) {
System.out.println("What mascot belongs to the University of Oklahoma?");
schoolQuestion3 = scan.next();
if (schoolQuestion3.equalsIgnoreCase("Sooners")){
score++;
}
else if (schoolQuestion3.equalsIgnoreCase("don't know")){
score = score + 0;
}
else {
score --;
}
}
else {
System.out.println("What mascot belongs to the University of Wisconsin?");
schoolQuestion4 = scan.next();
if (schoolQuestion4.equalsIgnoreCase("Wolverines")){
score++;
}
else if (schoolQuestion4.equalsIgnoreCase("don't know")){
score = score + 0;
}
else {
score --;
}
}
}
else {
questionCount = 5;
}
questionCount ++;
} while (questionCount <= 4);
System.out.println("\nBye. Your score is " + score);
}
}