Advertisement
Guest User

CPT_GAME_FINAL!!!

a guest
Jun 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 16.36 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.lang.Math;
  3. public class factTest2 {
  4.    
  5.     public static boolean MathAddition() {
  6.         Scanner input = new Scanner(System.in);
  7.         int number1, number2;
  8.         int userAnswer;
  9.  
  10.         number1 = (int)((21) * Math.random() + 1);
  11.         number2 = (int)((21) * Math.random() + 1);
  12.        
  13.         System.out.print("What is: " + number1 + " + " + number2 + " ?");
  14.         userAnswer = input.nextInt();
  15.    
  16.         if (userAnswer == (number1 + number2)) {
  17.             System.out.print("Correct! (+1 point)" + "\n");
  18.             return(true);
  19.         } else {
  20.             System.out.print("Wrong!" + "\n");
  21.             System.out.print("The correct answer was: " + (number1 + number2) + "\n");
  22.             return(false);
  23.         }
  24.     }
  25.    
  26.     public static boolean MathSubtraction() {
  27.         Scanner input = new Scanner(System.in);
  28.         int number1, number2;
  29.         int userAnswer;
  30.  
  31.         number1 = (int)((21) * Math.random() + 1);
  32.         number2 = (int)((21) * Math.random() + 1);
  33.        
  34.         System.out.print("What is: " + number1 + " - " + number2 + " ?");
  35.         userAnswer = input.nextInt();
  36.    
  37.         if (userAnswer == (number1 - number2)) {
  38.             System.out.print("Correct! (+1 point)" + "\n");
  39.             return(true);
  40.         } else {
  41.             System.out.print("Wrong!" + "\n");
  42.             System.out.print("The correct answer was: " + (number1 - number2) + "\n");
  43.             return(false);
  44.         }
  45.     }
  46.    
  47.     public static boolean MathMultiplication() {
  48.         Scanner input = new Scanner(System.in);
  49.         int number1, number2;
  50.         int userAnswer;
  51.  
  52.         number1 = (int)((9) * Math.random() + 1);
  53.         number2 = (int)((9) * Math.random() + 1);
  54.        
  55.         System.out.print("What is: " + number1 + " * " + number2 + " ?");
  56.         userAnswer = input.nextInt();
  57.    
  58.         if (userAnswer == (number1 * number2)) {
  59.             System.out.print("Correct! (+1 point)" + "\n");
  60.             return(true);
  61.         } else {
  62.             System.out.print("Wrong!" + "\n");
  63.             System.out.print("The correct answer was: " + (number1 * number2) + "\n");
  64.             return(false);
  65.         }
  66.     }
  67.  
  68.     public static boolean MathDivision() {
  69.         Scanner input = new Scanner(System.in);
  70.         int number1, number2;
  71.         double userAnswer;
  72.  
  73.         do {
  74.         number1 = (int)((9) * Math.random() + 1);
  75.         number2 = (int)((9) * Math.random() + 1);  
  76.         } while (number1 % number2 != 0);
  77.        
  78.        
  79.         System.out.print("What is: " + number1 + " / " + number2 + " ?");
  80.         userAnswer = input.nextInt();
  81.    
  82.         if (userAnswer == (number1 / number2)) {
  83.             System.out.print("Correct! (+1 point)" + "\n");
  84.             return(true);
  85.         } else {
  86.             System.out.print("Wrong!" + "\n");
  87.             System.out.print("The correct answer was: " + (number1 / number2) + "\n");
  88.             return(false);
  89.         }
  90.        
  91.     }
  92.    
  93.     public static boolean mathSelector() {
  94.        
  95.         int randomSelect;
  96.         boolean rightOrWrong = false;
  97.         randomSelect = (int)(4 * Math.random() + 1);
  98.        
  99.         switch(randomSelect) {
  100.         case 1: if (MathAddition() == true) {
  101.                     rightOrWrong = true;
  102.                 } else {
  103.                     rightOrWrong = false;
  104.                 }   break;
  105.         case 2: if (MathSubtraction() == true) {
  106.                     rightOrWrong = true;
  107.                 } else {
  108.                     rightOrWrong = false;
  109.                 }   break;
  110.         case 3: if (MathMultiplication() == true) {
  111.                 rightOrWrong = true;
  112.                 } else {
  113.                 rightOrWrong = false;
  114.                 }   break;
  115.         case 4: if (MathDivision() == true) {
  116.                 rightOrWrong = true;
  117.                 } else {
  118.                 rightOrWrong = false;
  119.                 }   break;
  120.         }
  121.         return(rightOrWrong);
  122.     }
  123.    
  124.     public static boolean factOne() {
  125.        
  126.         Scanner input = new Scanner(System.in);
  127.         String userAnswer;
  128.         String hintTrigger = "hint";
  129.         String hintAnswer = "Somewhere cold...";
  130.         String correctAnswer = "Antartica";
  131.        
  132.         System.out.print("What is the only continent without bees (type 'hint' for hint): ");
  133.         userAnswer = input.nextLine();
  134.        
  135.         if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  136.             System.out.print("Correct! (+1 point)");
  137.             return(true);
  138.         } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
  139.             System.out.print(hintAnswer);
  140.             System.out.print("What is the only continent without bees: ");
  141.             userAnswer = input.nextLine();
  142.                 if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  143.                     System.out.print("Correct! (+1 point)");
  144.                     return(true);
  145.                 } else {
  146.                     System.out.print("Incorrect! (-1 point)");
  147.                     System.out.print("\n" + "The correct answer was: " + correctAnswer);
  148.                     return(false);
  149.                 }
  150.         } else {
  151.             System.out.print("Incorrect! (-1 point)");
  152.             System.out.print("\n" + "The correct answer was: " + correctAnswer);
  153.             return(false);
  154.         }
  155.     }
  156.    
  157.     public static boolean factTwo () {
  158.        
  159.         Scanner input = new Scanner(System.in);
  160.         String userAnswer;
  161.         String hintTrigger = "hint";
  162.         String hintAnswer = "Starts with K...";
  163.         String correctAnswer = "Kr";
  164.        
  165.         System.out.print("What is the chemical symbol for Krypton (type 'hint' for hint): ");
  166.         userAnswer = input.nextLine();
  167.        
  168.         if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  169.             System.out.print("Correct! (+1 point)");
  170.             return(true);
  171.         } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
  172.             System.out.print(hintAnswer);
  173.             System.out.print("What is the cheimcal symbol for Krypton");
  174.             userAnswer = input.nextLine();
  175.                 if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  176.                     System.out.print("Correct! (+1 point)");
  177.                     return(true);
  178.                 } else {
  179.                     System.out.print("Incorrect! (-1 point)");
  180.                     System.out.print("\n" + "The correct answer was: " + correctAnswer);
  181.                     return(false);
  182.                 }
  183.         } else {
  184.             System.out.print("Incorrect! (-1 point)");
  185.             System.out.print("\n" + "The correct answer was: " + correctAnswer);
  186.             return(false);
  187.         }
  188.     }
  189.    
  190.     public static boolean factThree() {
  191.        
  192.         Scanner input = new Scanner(System.in);
  193.         String userAnswer;
  194.         String hintTrigger = "hint";
  195.         String hintAnswer = "End of a pizza...";
  196.         String correctAnswer = "Crust";
  197.        
  198.         System.out.print("What is the top, outer layer of the Earth (type 'hint' for hint): ");
  199.         userAnswer = input.nextLine();
  200.        
  201.         if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  202.             System.out.print("Correct! (+1 point)");
  203.             return(true);
  204.         } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
  205.             System.out.print(hintAnswer);
  206.             System.out.print("What is the top, outer layer of the Earth: ");
  207.             userAnswer = input.nextLine();
  208.                 if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  209.                     System.out.print("Correct! (+1 point)");
  210.                     return(true);
  211.                 } else {
  212.                     System.out.print("Incorrect! (-1 point)");
  213.                     System.out.print("\n" + "The correct answer was: " + correctAnswer);
  214.                     return(false);
  215.                 }
  216.         } else {
  217.             System.out.print("Incorrect! (-1 point)");
  218.             System.out.print("\n" + "The correct answer was: " + correctAnswer);
  219.             return(false);
  220.         }
  221.     }
  222.    
  223.     public static boolean factFour () {
  224.        
  225.         Scanner input = new Scanner(System.in);
  226.         String userAnswer;
  227.         String hintTrigger = "hint";
  228.         String hintAnswer = "Cold/Hot...";
  229.         String correctAnswer = "Temperature";
  230.        
  231.         System.out.print("What does the Kelvin scale measure (type 'hint' for hint): ");
  232.         userAnswer = input.nextLine();
  233.        
  234.         if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  235.             System.out.print("Correct! (+1 point)");
  236.             return(true);
  237.         } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
  238.             System.out.print(hintAnswer);
  239.             System.out.print("What does the Kelvin scale measure: ");
  240.             userAnswer = input.nextLine();
  241.                 if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  242.                     System.out.print("Correct! (+1 point)");
  243.                     return(true);
  244.                 } else {
  245.                     System.out.print("Incorrect! (-1 point)");
  246.                     System.out.print("\n" + "The correct answer was: " + correctAnswer);
  247.                     return(false);
  248.                 }
  249.         } else {
  250.             System.out.print("Incorrect! (-1 point)");
  251.             System.out.print("\n" + "The correct answer was: " + correctAnswer);
  252.             return(false);
  253.         }
  254.     }
  255.    
  256.     public static boolean factFive () {
  257.        
  258.         Scanner input = new Scanner(System.in);
  259.         String userAnswer;
  260.         String hintTrigger = "hint";
  261.         String hintAnswer = "Not automobiles, two words... ";
  262.         String correctAnswer = "Being Alone";
  263.        
  264.         System.out.print("Autophobia is the fear of what (type 'hint' for hint): ");
  265.         userAnswer = input.nextLine();
  266.        
  267.         if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  268.             System.out.print("Correct! (+1 point)");
  269.             return(true);
  270.         } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
  271.             System.out.print(hintAnswer);
  272.             System.out.print("Autophobia is the fear of what: ");
  273.             userAnswer = input.nextLine();
  274.                 if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  275.                     System.out.print("Correct! (+1 point)");
  276.                     return(true);
  277.                 } else {
  278.                     System.out.print("Incorrect! (-1 point)");
  279.                     System.out.print("\n" + "The correct answer was: " + correctAnswer);
  280.                     return(false);
  281.                 }
  282.         } else {
  283.             System.out.print("Incorrect! (-1 point)");
  284.             System.out.print("\n" + "The correct answer was: " + correctAnswer);
  285.             return(false);
  286.         }
  287.     }
  288.    
  289.     public static boolean factSix() {
  290.        
  291.         Scanner input = new Scanner(System.in);
  292.         String userAnswer;
  293.         String hintTrigger = "hint";
  294.         String hintAnswer = "One chases the other...";
  295.         String correctAnswer = "Cat and Mouse";
  296.        
  297.         System.out.print("What animals are Tom and Jerry (type 'hint' for hint): ");
  298.         userAnswer = input.nextLine();
  299.        
  300.         if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  301.             System.out.print("Correct! (+1 point)");
  302.             return(true);
  303.         } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
  304.             System.out.print(hintAnswer);
  305.             System.out.print("What animals are Tom and Jerry: ");
  306.             userAnswer = input.nextLine();
  307.                 if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  308.                     System.out.print("Correct! (+1 point)");
  309.                     return(true);
  310.                 } else {
  311.                     System.out.print("Incorrect! (-1 point)");
  312.                     System.out.print("\n" + "The correct answer was: " + correctAnswer);
  313.                     return(false);
  314.                 }
  315.         } else {
  316.             System.out.print("Incorrect! (-1 point)");
  317.             System.out.print("\n" + "The correct answer was: " + correctAnswer);
  318.             return(false);
  319.         }
  320.     }
  321.    
  322.     public static boolean factSeven() {
  323.        
  324.         Scanner input = new Scanner(System.in);
  325.         String userAnswer;
  326.         String hintTrigger = "hint";
  327.         String hintAnswer = "Not Two...";
  328.         String correctAnswer = "One";
  329.        
  330.         System.out.print("How many feet do snails have (type 'hint' for hint): ");
  331.         userAnswer = input.nextLine();
  332.        
  333.         if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  334.             System.out.print("Correct! (+1 point)");
  335.             return(true);
  336.         } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
  337.             System.out.print(hintAnswer);
  338.             System.out.print("How many feet do snails have: ");
  339.             userAnswer = input.nextLine();
  340.                 if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  341.                     System.out.print("Correct! (+1 point)");
  342.                     return(true);
  343.                 } else {
  344.                     System.out.print("Incorrect! (-1 point)");
  345.                     System.out.print("\n" + "The correct answer was: " + correctAnswer);
  346.                     return(false);
  347.                 }
  348.         } else {
  349.             System.out.print("Incorrect! (-1 point)");
  350.             System.out.print("\n" + "The correct answer was: " + correctAnswer);
  351.             return(false);
  352.         }
  353.     }
  354.    
  355.     public static boolean factEight() {
  356.        
  357.         Scanner input = new Scanner(System.in);
  358.         String userAnswer;
  359.         String hintTrigger = "hint";
  360.         String hintAnswer = "O ' '...";
  361.         String correctAnswer = "O Canada";
  362.        
  363.         System.out.print("What is the national anthem of Canada (type 'hint' for hint): ");
  364.         userAnswer = input.nextLine();
  365.        
  366.         if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  367.             System.out.print("Correct! (+1 point)");
  368.             return(true);
  369.         } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
  370.             System.out.print(hintAnswer);
  371.             System.out.print("What is the national anthem of Canada: ");
  372.             userAnswer = input.nextLine();
  373.                 if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  374.                     System.out.print("Correct! (+1 point)");
  375.                     return(true);
  376.                 } else {
  377.                     System.out.print("Incorrect! (-1 point)");
  378.                     System.out.print("\n" + "The correct answer was: " + correctAnswer);
  379.                     return(false);
  380.                 }
  381.         } else {
  382.             System.out.print("Incorrect! (-1 point)");
  383.             System.out.print("\n" + "The correct answer was: " + correctAnswer);
  384.             return(false);
  385.         }
  386.     }
  387.    
  388.     public static boolean factNine() {
  389.        
  390.         Scanner input = new Scanner(System.in);
  391.         String userAnswer;
  392.         String hintTrigger = "hint";
  393.         String hintAnswer = "Soda?...";
  394.         String correctAnswer = "Pop";
  395.        
  396.         System.out.print("Micheal Jackson was named the king of what (type 'hint' for hint): ");
  397.         userAnswer = input.nextLine();
  398.        
  399.         if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  400.             System.out.print("Correct! (+1 point)");
  401.             return(true);
  402.         } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
  403.             System.out.print(hintAnswer);
  404.             System.out.print("Micheal Jackson was named the king of what: ");
  405.             userAnswer = input.nextLine();
  406.                 if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  407.                     System.out.print("Correct! (+1 point)");
  408.                     return(true);
  409.                 } else {
  410.                     System.out.print("Incorrect! (-1 point)");
  411.                     System.out.print("\n" + "The correct answer was: " + correctAnswer);
  412.                     return(false);
  413.                 }
  414.         } else {
  415.             System.out.print("Incorrect! (-1 point)");
  416.             System.out.print("\n" + "The correct answer was: " + correctAnswer);
  417.             return(false);
  418.         }
  419.     }
  420.    
  421.     public static boolean factTen () {
  422.        
  423.         Scanner input = new Scanner(System.in);
  424.         String userAnswer;
  425.         String hintTrigger = "hint";
  426.         String hintAnswer = "Coffee...";
  427.         String correctAnswer = "Java";
  428.        
  429.         System.out.print("What program was this game coded on (type 'hint' for hint): ");
  430.         userAnswer = input.nextLine();
  431.        
  432.         if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  433.             System.out.print("Correct! (+1 point)");
  434.             return(true);
  435.         } else if (userAnswer.equalsIgnoreCase(hintTrigger)) {
  436.             System.out.print(hintAnswer);
  437.             System.out.print("What program was this game coded on: ");
  438.             userAnswer = input.nextLine();
  439.                 if (userAnswer.equalsIgnoreCase(correctAnswer)) {
  440.                     System.out.print("Correct! (+1 point)");
  441.                     return(true);
  442.                 } else {
  443.                     System.out.print("Incorrect! (-1 point)");
  444.                     System.out.print("\n" + "The correct answer was: " + correctAnswer);
  445.                     return(false);
  446.                 }
  447.         } else {
  448.             System.out.print("Incorrect! (-1 point)");
  449.             System.out.print("\n" + "The correct answer was: " + correctAnswer);
  450.             return(false);
  451.         }
  452.     }
  453.    
  454.    
  455.     public static boolean factSelector() {
  456.        
  457.         int randomSelect;
  458.         boolean rightOrWrong = false;
  459.         randomSelect = (int)(10 * Math.random() + 1);
  460.        
  461.         switch(randomSelect) {
  462.         case 1: if (factOne() == true) {
  463.                     rightOrWrong = true;
  464.                 } else {
  465.                     rightOrWrong = false;
  466.                 }   break;
  467.         case 2: if (factTwo() == true) {
  468.                     rightOrWrong = true;
  469.                 } else {
  470.                     rightOrWrong = false;
  471.                 }   break;
  472.         case 3: if (factThree() == true) {
  473.                 rightOrWrong = true;
  474.                 } else {
  475.                 rightOrWrong = false;
  476.                 }   break;
  477.         case 4: if (factFour() == true) {
  478.                 rightOrWrong = true;
  479.                 } else {
  480.                 rightOrWrong = false;
  481.                 }   break;
  482.         case 5: if (factFive() == true) {
  483.                 rightOrWrong = true;
  484.                 } else {
  485.                 rightOrWrong = false;
  486.             }   break;
  487.         case 6: if (factSix() == true) {
  488.                 rightOrWrong = true;
  489.                 } else {
  490.                 rightOrWrong = false;
  491.                 }   break;
  492.         case 7: if (factSeven() == true) {
  493.                 rightOrWrong = true;
  494.                 } else {
  495.                     rightOrWrong = false;
  496.                 }   break;
  497.         case 8: if (factEight() == true) {
  498.                 rightOrWrong = true;
  499.                 } else {
  500.                 rightOrWrong = false;
  501.                 }   break;
  502.         case 9: if (factNine() == true) {
  503.                 rightOrWrong = true;
  504.                 } else {
  505.                 rightOrWrong = false;
  506.                 }   break;
  507.         case 10: if (factTen() == true) {
  508.                 rightOrWrong = true;
  509.                 } else {
  510.                 rightOrWrong = false;
  511.                 }   break;
  512.         }
  513.         return(rightOrWrong);
  514.     }
  515.  
  516.    
  517.     public static void main(String[] args) {
  518.        
  519.         int levelSelection;
  520.         int rightCounter = 0;
  521.         int wrongCounter = 0;
  522.        
  523.         System.out.print("Start Game" + "\n\n");
  524.        
  525.         do {
  526.         levelSelection = (int)(5 * Math.random() + 1);
  527.         switch (levelSelection) {
  528.         case 1:
  529.             if (mathSelector() == true) {
  530.             rightCounter += 1;
  531.             } else {
  532.                 wrongCounter += 1;
  533.             }
  534.             System.out.print("\n\n" + "rightCounter in main is = " + rightCounter + "\n");
  535.             System.out.print("wrongCounter in main is = " + wrongCounter + "\n\n");
  536.             break;
  537.  
  538.         case 2:
  539.             if (factSelector() == true) {
  540.             rightCounter += 1;
  541.             } else {
  542.                 wrongCounter += 1;
  543.             }
  544.             System.out.print("\n\n" + "rightCounter in main is = " + rightCounter + "\n");
  545.             System.out.print("wrongCounter in main is = " + wrongCounter + "\n\n");
  546.             break;
  547.     }
  548.        
  549.     } while (rightCounter != 10 && wrongCounter != 3);
  550.    
  551.         if (rightCounter == 10) {
  552.             System.out.print("Congrats. You Win!!");
  553.         } else if (wrongCounter == 3) {
  554.             System.out.print("Sorry, You Lose!!");
  555.         }
  556.     }
  557. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement