So, when I run my code, it won't run as expected.
My program asks you to enter 10 questions than 10 answers to go be quizzed on. When I enter the correct answer when I'm getting quizzed on, it will pop up to the else statement. Yes, I am aware that this CODE is really messy and using if and else statements make my code horrible. It is spaghetti code and I KNOW ill soon hopefully fix it later.
package com.ez.ez;
import java.util.Scanner;
public class Quiz{
public static void main (String[] args) {
System.out.println("Welcome to my quiz program!");
Scanner scanner = new Scanner(System.in);
System.out.println("Would you like to create a key?");
String yesKeyOrNoKey = scanner.nextLine();
if (yesKeyOrNoKey.equalsIgnoreCase("Yes") || yesKeyOrNoKey.equalsIgnoreCase("True")) {
System.out.println("Welcome! simply enter the QUESTIONS below, (They're 10 questions must be completed to run normal!))");
System.out.println("What is your first question?");
String firstQuestion = scanner.nextLine();
System.out.println("What is your second question?");
String secondQuestion = scanner.nextLine();
System.out.println("What is your third question?");
String thirdQuestion = scanner.nextLine();
System.out.println("What is your fourth question?");
String fourthdQuestion = scanner.nextLine();
System.out.println("What is your fifth question?");
String fifthQuestion = scanner.nextLine();
System.out.println("What is your sixth question?");
String sixthQuestion = scanner.nextLine();
System.out.println("What is your seventh question?");
String seventhQuestion = scanner.nextLine();
System.out.println("What is your eigth question?");
String eigthQuestion = scanner.nextLine();
System.out.println("What is your ninth question?");
String ninthQuestion = scanner.nextLine();
System.out.println("What is your tenth question?");
String tenthQuestion = scanner.nextLine();
System.out.println();
System.out.println();
System.out.println("Enter answer one");
String answerOne = scanner.nextLine();
System.out.println("Enter answer two");
String answerTwo = scanner.nextLine();
System.out.println("Enter answer three");
String answerThree = scanner.nextLine();
System.out.println("Enter answer four");
String answerFour = scanner.nextLine();
System.out.println("Enter answer five");
String answerFive = scanner.nextLine();
System.out.println("Enter answer six");
String answerSix = scanner.nextLine();
System.out.println("Enter answer seven");
String answerSeven = scanner.nextLine();
System.out.println("Enter answer eight");
String answerEight = scanner.nextLine();
System.out.println("Enter answer nine");
String answerNine = scanner.nextLine();
System.out.println("Enter answer ten");
String answerTen = scanner.nextLine();
System.out.println("Are you ready? to start your quiz!?");
String readyKey = scanner.nextLine();
if(readyKey.equalsIgnoreCase("Yes") || readyKey.equalsIgnoreCase("TRUE")) {
System.out.println("AMAZING!");
System.out.println();
System.out.println(firstQuestion);
String yourAnswerOne = scanner.nextLine();
if (yourAnswerOne == answerOne) {
System.out.println("Congrats! you made it passed level 1! 1/10 ");
System.out.println(secondQuestion);
String yourAnswerTwo = scanner.nextLine();
if(yourAnswerTwo == answerTwo) {
System.out.println("Congrats you had made it passed level 2! 2/10");
System.out.println(thirdQuestion);
String yourAnswerThree = scanner.nextLine();
if(yourAnswerThree == answerThree) {
System.out.println("Suprisingly did not fail third round! congrats! 3/10");
System.out.println(fourthdQuestion);
String yourAnswerFour = scanner.nextLine();
if(yourAnswerFour == answerFour) {
System.out.println("Amazing! your not done buddy 4/10 you can do it");
System.out.println(fifthQuestion);
String yourAnswerFive = scanner.nextLine();
if(yourAnswerFive == answerFive) {
System.out.println("Half way done! keep it up!");
System.out.println(sixthQuestion);
String yourAnswerSix = scanner.nextLine();
if(yourAnswerSix == answerSix) {
System.out.println("Congrats 4 more to go!");
System.out.println(seventhQuestion);
String yourAnswerSeven = scanner.nextLine();
if(yourAnswerSeven == answerSeven) {
System.out.println("Congrats 7/10! 3 more to go" );
System.out.println(eigthQuestion);
String yourAnswerEight = scanner.nextLine();
if( yourAnswerEight == answerEight) {
System.out.println("2 more up and your set to go! 8/10");
System.out.println(ninthQuestion);
String yourAnswerNine = scanner.nextLine();
if(yourAnswerNine == answerNine) {
System.out.println("ONE MORE!! YOUR SO CLOSE!");
System.out.println(tenthQuestion);
String yourAnswerTen = scanner.nextLine();
if(yourAnswerTen == answerTen) {
System.out.println("CONGRATS YOU HAD MADE IT GOOD JOB!!!");
} else {
System.out.println("Unfortunate lol ");
}
} else {
System.out.println("NOOOO sad to see ya go Try again and maybe you can win!!");
}
} else {
System.out.println("YOU WERE SO CLOSE! try again and you may go up!");
}
} else {
System.out.println("So close! only if you made it up a notch!");
}
} else {
System.out.println("Maybe if you tried hard enough you coudve done better! good luck");
}
} else {
System.out.println("Thats a 50%, are you happy with that? 5/10");
}
} else {
System.out.println("Meh, close enough 4/10");
}
} else {
System.out.println("Sad to see you go bud");
}
} else {
System.out.println("Booohooo you did not make it that far!");
}
} else {
System.out.println("Sad to see you go! at the first level! 1/10");
}
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire