Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.lang.Math;
- public class factTest2 {
- public static boolean MathAddition() {
- Scanner input = new Scanner(System.in);
- int number1, number2;
- int userAnswer;
- number1 = (int)((21) * Math.random() + 1);
- number2 = (int)((21) * Math.random() + 1);
- System.out.print("What is: " + number1 + " + " + number2 + " ?");
- userAnswer = input.nextInt();
- if (userAnswer == (number1 + number2)) {
- System.out.print("Correct! (+1 point)" + "\n");
- return(true);
- } else {
- System.out.print("Wrong!" + "\n");
- System.out.print("The correct answer was: " + (number1 + number2) + "\n");
- return(false);
- }
- }
- public static boolean MathSubtraction() {
- Scanner input = new Scanner(System.in);
- int number1, number2;
- int userAnswer;
- number1 = (int)((21) * Math.random() + 1);
- number2 = (int)((21) * Math.random() + 1);
- System.out.print("What is: " + number1 + " - " + number2 + " ?");
- userAnswer = input.nextInt();
- if (userAnswer == (number1 - number2)) {
- System.out.print("Correct! (+1 point)" + "\n");
- return(true);
- } else {
- System.out.print("Wrong!" + "\n");
- System.out.print("The correct answer was: " + (number1 - number2) + "\n");
- return(false);
- }
- }
- public static boolean MathMultiplication() {
- Scanner input = new Scanner(System.in);
- int number1, number2;
- int userAnswer;
- number1 = (int)((9) * Math.random() + 1);
- number2 = (int)((9) * Math.random() + 1);
- System.out.print("What is: " + number1 + " * " + number2 + " ?");
- userAnswer = input.nextInt();
- if (userAnswer == (number1 * number2)) {
- System.out.print("Correct! (+1 point)" + "\n");
- return(true);
- } else {
- System.out.print("Wrong!" + "\n");
- System.out.print("The correct answer was: " + (number1 * number2) + "\n");
- return(false);
- }
- }
- public static boolean MathDivision() {
- Scanner input = new Scanner(System.in);
- int number1, number2;
- double userAnswer;
- do {
- number1 = (int)((9) * Math.random() + 1);
- number2 = (int)((9) * Math.random() + 1);
- } while (number1 % number2 != 0);
- System.out.print("What is: " + number1 + " / " + number2 + " ?");
- userAnswer = input.nextInt();
- if (userAnswer == (number1 / number2)) {
- System.out.print("Correct! (+1 point)" + "\n");
- return(true);
- } else {
- System.out.print("Wrong!" + "\n");
- System.out.print("The correct answer was: " + (number1 / number2) + "\n");
- return(false);
- }
- }
- public static boolean mathSelector() {
- int randomSelect;
- boolean rightOrWrong = false;
- randomSelect = (int)(4 * Math.random() + 1);
- switch(randomSelect) {
- case 1: if (MathAddition() == true) {
- rightOrWrong = true;
- } else {
- rightOrWrong = false;
- } break;
- case 2: if (MathSubtraction() == true) {
- rightOrWrong = true;
- } else {
- rightOrWrong = false;
- } break;
- case 3: if (MathMultiplication() == true) {
- rightOrWrong = true;
- } else {
- rightOrWrong = false;
- } break;
- case 4: if (MathDivision() == true) {
- rightOrWrong = true;
- } else {
- rightOrWrong = false;
- } break;
- }
- return(rightOrWrong);
- }
- public static boolean factOne() {
- Scanner input = new Scanner(System.in);
- String userAnswer;
- String hintTrigger = "hint";
- String hintAnswer = "Somewhere cold...";
- String correctAnswer = "Antartica";
- System.out.print("What is the only continent without bees (type 'hint' for hint): ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
- System.out.print(hintAnswer);
- System.out.print("What is the only continent without bees: ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- }
- public static boolean factTwo () {
- Scanner input = new Scanner(System.in);
- String userAnswer;
- String hintTrigger = "hint";
- String hintAnswer = "Starts with K...";
- String correctAnswer = "Kr";
- System.out.print("What is the chemical symbol for Krypton (type 'hint' for hint): ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
- System.out.print(hintAnswer);
- System.out.print("What is the cheimcal symbol for Krypton");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- }
- public static boolean factThree() {
- Scanner input = new Scanner(System.in);
- String userAnswer;
- String hintTrigger = "hint";
- String hintAnswer = "End of a pizza...";
- String correctAnswer = "Crust";
- System.out.print("What is the top, outer layer of the Earth (type 'hint' for hint): ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
- System.out.print(hintAnswer);
- System.out.print("What is the top, outer layer of the Earth: ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- }
- public static boolean factFour () {
- Scanner input = new Scanner(System.in);
- String userAnswer;
- String hintTrigger = "hint";
- String hintAnswer = "Cold/Hot...";
- String correctAnswer = "Temperature";
- System.out.print("What does the Kelvin scale measure (type 'hint' for hint): ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
- System.out.print(hintAnswer);
- System.out.print("What does the Kelvin scale measure: ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- }
- public static boolean factFive () {
- Scanner input = new Scanner(System.in);
- String userAnswer;
- String hintTrigger = "hint";
- String hintAnswer = "Not automobiles, two words... ";
- String correctAnswer = "Being Alone";
- System.out.print("Autophobia is the fear of what (type 'hint' for hint): ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
- System.out.print(hintAnswer);
- System.out.print("Autophobia is the fear of what: ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- }
- public static boolean factSix() {
- Scanner input = new Scanner(System.in);
- String userAnswer;
- String hintTrigger = "hint";
- String hintAnswer = "One chases the other...";
- String correctAnswer = "Cat and Mouse";
- System.out.print("What animals are Tom and Jerry (type 'hint' for hint): ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
- System.out.print(hintAnswer);
- System.out.print("What animals are Tom and Jerry: ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- }
- public static boolean factSeven() {
- Scanner input = new Scanner(System.in);
- String userAnswer;
- String hintTrigger = "hint";
- String hintAnswer = "Not Two...";
- String correctAnswer = "One";
- System.out.print("How many feet do snails have (type 'hint' for hint): ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
- System.out.print(hintAnswer);
- System.out.print("How many feet do snails have: ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- }
- public static boolean factEight() {
- Scanner input = new Scanner(System.in);
- String userAnswer;
- String hintTrigger = "hint";
- String hintAnswer = "O ' '...";
- String correctAnswer = "O Canada";
- System.out.print("What is the national anthem of Canada (type 'hint' for hint): ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
- System.out.print(hintAnswer);
- System.out.print("What is the national anthem of Canada: ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- }
- public static boolean factNine() {
- Scanner input = new Scanner(System.in);
- String userAnswer;
- String hintTrigger = "hint";
- String hintAnswer = "Soda?...";
- String correctAnswer = "Pop";
- System.out.print("Micheal Jackson was named the king of what (type 'hint' for hint): ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
- System.out.print(hintAnswer);
- System.out.print("Micheal Jackson was named the king of what: ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- }
- public static boolean factTen () {
- Scanner input = new Scanner(System.in);
- String userAnswer;
- String hintTrigger = "hint";
- String hintAnswer = "Coffee...";
- String correctAnswer = "Java";
- System.out.print("What program was this game coded on (type 'hint' for hint): ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
- System.out.print(hintAnswer);
- System.out.print("What program was this game coded on: ");
- userAnswer = input.nextLine();
- if (userAnswer.equalsIgnoreCase(correctAnswer)) {
- System.out.print("Correct! (+1 point)");
- return(true);
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- } else {
- System.out.print("Incorrect! (-1 point)");
- System.out.print("\n" + "The correct answer was: " + correctAnswer);
- return(false);
- }
- }
- public static boolean factSelector() {
- int randomSelect;
- boolean rightOrWrong = false;
- randomSelect = (int)(10 * Math.random() + 1);
- switch(randomSelect) {
- case 1: if (factOne() == true) {
- rightOrWrong = true;
- } else {
- rightOrWrong = false;
- } break;
- case 2: if (factTwo() == true) {
- rightOrWrong = true;
- } else {
- rightOrWrong = false;
- } break;
- case 3: if (factThree() == true) {
- rightOrWrong = true;
- } else {
- rightOrWrong = false;
- } break;
- case 4: if (factFour() == true) {
- rightOrWrong = true;
- } else {
- rightOrWrong = false;
- } break;
- case 5: if (factFive() == true) {
- rightOrWrong = true;
- } else {
- rightOrWrong = false;
- } break;
- case 6: if (factSix() == true) {
- rightOrWrong = true;
- } else {
- rightOrWrong = false;
- } break;
- case 7: if (factSeven() == true) {
- rightOrWrong = true;
- } else {
- rightOrWrong = false;
- } break;
- case 8: if (factEight() == true) {
- rightOrWrong = true;
- } else {
- rightOrWrong = false;
- } break;
- case 9: if (factNine() == true) {
- rightOrWrong = true;
- } else {
- rightOrWrong = false;
- } break;
- case 10: if (factTen() == true) {
- rightOrWrong = true;
- } else {
- rightOrWrong = false;
- } break;
- }
- return(rightOrWrong);
- }
- public static void main(String[] args) {
- int levelSelection;
- int rightCounter = 0;
- int wrongCounter = 0;
- System.out.print("Start Game" + "\n\n");
- do {
- levelSelection = (int)(5 * Math.random() + 1);
- switch (levelSelection) {
- case 1:
- if (mathSelector() == true) {
- rightCounter += 1;
- } else {
- wrongCounter += 1;
- }
- System.out.print("\n\n" + "rightCounter in main is = " + rightCounter + "\n");
- System.out.print("wrongCounter in main is = " + wrongCounter + "\n\n");
- break;
- case 2:
- if (factSelector() == true) {
- rightCounter += 1;
- } else {
- wrongCounter += 1;
- }
- System.out.print("\n\n" + "rightCounter in main is = " + rightCounter + "\n");
- System.out.print("wrongCounter in main is = " + wrongCounter + "\n\n");
- break;
- }
- } while (rightCounter != 10 && wrongCounter != 3);
- if (rightCounter == 10) {
- System.out.print("Congrats. You Win!!");
- } else if (wrongCounter == 3) {
- System.out.print("Sorry, You Lose!!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement