Advertisement
Guest User

Untitled

a guest
Jan 15th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.44 KB | None | 0 0
  1. /* Trivial Pursuit
  2. * This program is a 2 player game which is a modified version of Trivial Pursuit
  3. * @author Stas Dragoman
  4. * @author James Vu
  5. * Date last modified: January 15th, 2019
  6. */
  7.  
  8. import java.util.*;
  9. class TrivialPusuitFinalProject
  10. {
  11. public static void main(String args[])
  12. {
  13. Scanner kbReader = new Scanner(System.in);
  14. Scanner kbReader1 = new Scanner(System.in);
  15. Scanner kbReader2 = new Scanner(System.in);
  16. Scanner kbReader3 = new Scanner(System.in);
  17.  
  18. System.out.println ("This is a trivia game in which you have to pick a package of questions and answer each one. It is meant for 2 players.");
  19. System.out.println ("At the end, the scores will be displayed. Each question is worth 1 point.");
  20.  
  21. System.out.println("Enter the first player name: ");
  22. String player1 = kbReader.nextLine();
  23. System.out.println("Hi "+player1);
  24. System.out.println("Enter the second player name: ");
  25. String player2 = kbReader.nextLine();
  26. System.out.println(" Hello "+player2);
  27.  
  28. int scores1 = 0;
  29. int scores2 = 0;
  30. int qCounter = 0;
  31.  
  32. for(int k = 0; k<4; k++){
  33. qCounter = 0;
  34. // Resets the question counter so that it doesn't start from the top when it loops
  35.  
  36. System.out.println("Do you want to continue ? Y/N");
  37. char continueGame = kbReader.next().charAt(0);
  38. if(continueGame == 'Y' || continueGame == 'y'){
  39.  
  40. System.out.println(" Enjoy the game :D ");
  41. System.out.println(" There are 5 packages of question, so pick a number from 1 to 5 to choose which one you want to answer.");
  42.  
  43. int bag = kbReader.nextInt();
  44. if(bag==1){
  45.  
  46. for(int i = 0; i < 10; i++){
  47.  
  48. String[] questions = {" What nationality was Chopin?", "What's the best known artificial international language?", "Who lived at 221B, Baker Street, London?", "Who cut Van Gogh's ear?", "Which city did Salvador Dali live in?", "Who painted the Mona Lisa?", "What Spanish artist said he would eat his wife when she died?", "Who wrote Julius Caesar, Macbeth and Hamlet?", "Who wrote Lazarillo de Tormes?", "What did the crocodile swallow in Peter Pan?" };
  49. String[] answers = {"polish", "esperanto", "Sherlock Holmes", "he did", "Figueres", "Da Vinci","Dali","Shakespeare", "anonymous", "alarm clock"};
  50. String[] answers1 = {"he was polish", "?", "?", "van gogh", "Figueres, Spain", "Leonardo Da Vinci", "Salvador Dali", "William Shakespeare", "?", "an alarm clock"};
  51. String[] answers2 = {"?", "?", "?", "himself", "?", "?", "?", "?", "?", "?"};
  52. // Stars are used here to further the array number and because you can not make them with a regular keyboard
  53.  
  54. qCounter = qCounter + 1;
  55. // This question counter is what makes it display the next question in the loop
  56.  
  57. System.out.println(questions[qCounter-1]);
  58. String answer1 = kbReader1.nextLine();
  59. if(answer1.equalsIgnoreCase(answers[qCounter-1])|| answer1.equalsIgnoreCase(answers1[qCounter-1])|| answer1.equalsIgnoreCase(answers2[qCounter-1])){
  60. System.out.println("Correct!");
  61. scores1 = scores1 + 1;
  62. System.out.println(player1 +": "+ scores1);
  63. }
  64.  
  65. else{
  66.  
  67. System.out.println("incorrect!");
  68. System.out.println("Do you want to answer this question? Y/N");
  69. char choice1 = kbReader3.next().charAt(0);
  70.  
  71. if(choice1 =='Y' || choice1 == 'y'){
  72.  
  73. System.out.println("Enter your answer: ");
  74. String answer2 = kbReader2.nextLine();
  75. System.out.println(answer2);
  76.  
  77. if(answer2.equalsIgnoreCase(answers[qCounter-1])){
  78. System.out.println("Correct!");
  79. scores2 = scores2 + 1;
  80. System.out.println(player2 +": "+ scores2);
  81. }
  82.  
  83. else{
  84.  
  85. scores2 = scores2 -1;
  86. System.out.println(player2 +": "+ scores2);
  87. System.out.println("The answer is: " + answers[qCounter-1]);
  88. }
  89. }
  90. }
  91. }
  92.  
  93. int temp = scores1;
  94. scores1 = scores2;
  95. scores2 = temp;
  96. String temp1 = player1;
  97. player1 = player2;
  98. player2 = temp1;
  99. // This chunk of commands switches the scores when its player 2's turn
  100. }
  101.  
  102. else if(bag==2){
  103.  
  104. for(int i = 0; i < 10; i++){
  105.  
  106. String[] questions = {" Which nail grows fastest?", "What temperature, in celsius does water boil at?","Who discovered penicillin?", "What is the largest European country located entirely within Europe?", "How many states are there in the United States of America?","What year did the Spanish Civil War end?","When did the First World War start?","Where is the smallest bone in the body?", "Which is the only mammal that can’t jump?","What colour is a panda?"};
  107. String[] answers = {"middle","100", "Fleming", "Ukraine", "50","1939"," 1914","stapes","elephant", "black and white"};
  108. String[] answers1 = {"the middle finger", "100 degrees", "Alexander Fleming", "?", "?", "?", "?", "the stapes", "?", "white and black"};
  109. String[] answers2 = {"the middle one", "100 c", "?", "?", "Fifty", "?", "?", "?", "?", "black & white"};
  110. String[] answers3 = {"?", "?", "?", "?", "?", "?", "?", "?", "?", "white & black"};
  111.  
  112. qCounter = qCounter + 1;
  113.  
  114. System.out.println(questions[qCounter-1]);
  115. String answer1 = kbReader1.nextLine();
  116.  
  117. if(answer1.equalsIgnoreCase(answers[qCounter-1])|| answer1.equalsIgnoreCase(answers1[qCounter-1])|| answer1.equalsIgnoreCase(answers2[qCounter-1])|| answer1.equalsIgnoreCase(answers3[qCounter-1])){
  118. System.out.println("Correct!");
  119. scores1 = scores1 + 1;
  120. System.out.println(player1 +": "+ scores1);
  121. }
  122.  
  123. else{
  124.  
  125. System.out.println("incorrect!");
  126. System.out.println("Do you want to answer this question? Y/N");
  127. char choice1 = kbReader3.next().charAt(0);
  128.  
  129. if(choice1 =='Y' || choice1 == 'y'){
  130.  
  131. System.out.println("Enter your answer: ");
  132. String answer2 = kbReader2.nextLine();
  133. System.out.println(answer2);
  134.  
  135. if(answer2.equalsIgnoreCase(answers[qCounter-1])){
  136.  
  137. System.out.println("Correct!");
  138. scores2 = scores2 + 1;
  139. System.out.println(player2 +": "+ scores2);
  140. }
  141.  
  142. else{
  143.  
  144. scores2 = scores2 -1;
  145. System.out.println(player2 +": "+ scores2);
  146. System.out.println("The answer is: " + answers[qCounter-1]);
  147. }
  148. }
  149. }
  150. }
  151.  
  152. int temp = scores1;
  153. scores1 = scores2;
  154. scores2 = temp;
  155. String temp1 = player1;
  156. player1 = player2;
  157. player2 = temp1;
  158.  
  159. }
  160.  
  161. else if(bag==3){
  162.  
  163. for(int i = 0; i < 10; i++){
  164.  
  165. String[] questions = {" How many squares are there on a chess board? ", "Who starts first in chess?"," What language has the most words?", "What currency is used in Japan? ", " Who as the main actor in “Cocktail”?","Who invented the electric light bulb?","What activity other than jumping are kangaroos good at?"," What colours make purple when combined?", "What’s the hardest mineral?","Where does the American president live?"};
  166. String[] answers = {"64","white", "English", "yen", "Tom Cruise","Thomas Edison","boxing","red and blue","diamond", "the white house"};
  167. String[] answers1 = {"sixty four", "the white side", "?", "the yen", "?", "Edison", "?", "?", "diamond", "in the white house"};
  168. qCounter = qCounter+1;
  169. System.out.println(questions[qCounter-1]);
  170. String answer1 = kbReader1.nextLine();
  171.  
  172. if(answer1.equalsIgnoreCase(answers[qCounter-1])|| answer1.equalsIgnoreCase(answers1[qCounter-1])){
  173.  
  174. System.out.println("Correct!");
  175. scores1 = scores1 + 1;
  176. System.out.println(player1 +": "+ scores1);
  177. }
  178.  
  179. else{
  180.  
  181. System.out.println("incorrect!");
  182. System.out.println("Do you want to answer this question? Y/N");
  183. char choice1 = kbReader3.next().charAt(0);
  184.  
  185. if(choice1 =='Y' || choice1 == 'y'){
  186.  
  187. System.out.println("Enter your answer: ");
  188. String answer2 = kbReader2.nextLine();
  189. System.out.println(answer2);
  190.  
  191. if(answer2.equalsIgnoreCase(answers[qCounter-1])){
  192.  
  193. System.out.println("Correct!");
  194. scores2 = scores2 + 1;
  195. System.out.println(player2 +": "+ scores2);
  196. }
  197.  
  198. else{
  199. scores2 = scores2 -1;
  200. System.out.println(player2 +": "+ scores2);
  201. System.out.println("The answer is: " + answers[qCounter-1]);
  202. }
  203. }
  204. }
  205. }
  206.  
  207. int temp = scores1;
  208. scores1 = scores2;
  209. scores2 = temp;
  210. String temp1 = player1;
  211. player1 = player2;
  212. player2 = temp1;
  213.  
  214. }
  215.  
  216. else if(bag==4){
  217.  
  218. for(int i = 0; i < 10; i++){
  219.  
  220. String[] questions = {"When did the last ice age end?", "Where is the largest statue in the world?","Who was the leader of Tsarist Russia at the beginning of the First World War?", "What song was number 1 on the billboard hot 100 for the longest time?", "Which country first hosted the winter olympics?","Which element is Cu on the periodic table of elements","How tall was the tallest man ever, in centimeters?","What European city are hamburgers named after", "Which American state is known as the Sunshine State","Who is considered the fastest man on Earth?"};
  221. String[] answers = {"11700 years ago","Henan, China", "Nicholas II", "Despacito", "France","Copper","2.72 meters tall","hamburg","florida", "Usain Bolt"};
  222. String[] answers1 = {"11000 years ago", "Henan","Nicolai II", "One Sweet Day", "?", "?", "272 centimeters tall", "?", "?", "?"};
  223. String[] answers2 = {"?", "?", "Nicholas the 2nd", "?", "?", "?", "272 cm tall", "?", "?", "?"};
  224. String[] answers3 = {"?", "?", "Nicholai the 2nd", "?", "?", "?", "272 cm", "?", "?", "?"};
  225.  
  226. qCounter = qCounter + 1;
  227.  
  228. System.out.println(questions[qCounter-1]);
  229. String answer1 = kbReader1.nextLine();
  230.  
  231. if(answer1.equalsIgnoreCase(answers[qCounter-1])|| answer1.equalsIgnoreCase(answers1[qCounter-1])|| answer1.equalsIgnoreCase(answers2[qCounter-1])|| answer1.equalsIgnoreCase(answers3[qCounter-1])){
  232.  
  233. System.out.println("Correct!");
  234. scores1 = scores1 + 1;
  235. System.out.println(player1 +": "+ scores1);
  236. }
  237.  
  238. else{
  239.  
  240. System.out.println("incorrect!");
  241. System.out.println("Do you want to answer this question? Y/N");
  242. char choice1 = kbReader3.next().charAt(0);
  243.  
  244. if(choice1 =='Y' || choice1 == 'y'){
  245.  
  246. System.out.println("Enter your answer: ");
  247. String answer2 = kbReader2.nextLine();
  248. System.out.println(answer2);
  249.  
  250. if(answer2.equalsIgnoreCase(answers[qCounter-1])){
  251.  
  252. System.out.println("Correct!");
  253. scores2 = scores2 + 1;
  254. System.out.println(player2 +": "+ scores2);
  255. }
  256.  
  257. else{
  258.  
  259. scores2 = scores2 -1;
  260. System.out.println(player2 +": "+ scores2);
  261. System.out.println("The answer is: " + answers[qCounter-1]);
  262. }
  263. }
  264. }
  265. }
  266.  
  267. int temp = scores1;
  268. scores1 = scores2;
  269. scores2 = temp;
  270. String temp1 = player1;
  271. player1 = player2;
  272.  
  273. player2 = temp1;
  274. }
  275. else if(bag==5){
  276.  
  277. for(int i = 0; i < 10; i++){
  278.  
  279. String[] questions = {"How many landlocked countries are there?", "How many teams are there in the NBA","Which continent is both a continent and also a country?", "When was Tim Hortons founded?", "What was the first publicly traded U.S. company to have a market cap of 1 trillion dollars?","Persia is another name for what country?","What is the capital city of Belgium?","How old was Batman in the Dark Knight?", "Which is the only mammal that can’t jump?","What kind of leaf is on the Canadian flag?"};
  280. String[] answers = {"49", "30", "Australia", "1964", "Apple","Iran","Brussels","40","elephant", "maple leaf"};
  281. String[] answers1 = {"forty nine", "?", "?", "?", "?", "?", "?", "forty", "the elephant", "the maple leaf"};
  282. String[] answers2 = {"forty-nine", "?", "?", "?", "?", "?", "?", "40 years old", "?", "maple"};
  283. String[] answers3 = {"?", "?", "?", "?", "?", "?", "?", "forty years old", "?", "?"};
  284.  
  285. qCounter = qCounter+1;
  286.  
  287. System.out.println(questions[qCounter-1]);
  288.  
  289. String answer1 = kbReader1.nextLine();
  290.  
  291. if(answer1.equalsIgnoreCase(answers[qCounter-1])|| answer1.equalsIgnoreCase(answers1[qCounter-1])|| answer1.equalsIgnoreCase(answers2[qCounter-1])|| answer1.equalsIgnoreCase(answers3[qCounter-1])){
  292.  
  293. System.out.println("Correct!");
  294. scores1 = scores1 + 1;
  295. System.out.println(player1 +": "+ scores1);
  296. }
  297.  
  298. else{
  299.  
  300. System.out.println("incorrect!");
  301. System.out.println("Do you want to answer this question? Y/N");
  302. char choice1 = kbReader3.next().charAt(0);
  303.  
  304. if(choice1 =='Y' || choice1 == 'y'){
  305.  
  306. System.out.println("Enter your answer: ");
  307. String answer2 = kbReader2.nextLine();
  308. System.out.println(answer2);
  309.  
  310. if(answer2.equalsIgnoreCase(answers[qCounter-1])){
  311.  
  312. System.out.println("Correct!");
  313. scores2 = scores2 + 1;
  314. System.out.println(player2 +": "+ scores2);
  315. }
  316.  
  317. else{
  318.  
  319. scores2 = scores2 -1;
  320. System.out.println(player2 +": "+ scores2);
  321. System.out.println("The answer is: " + answers[qCounter-1]);
  322. }
  323. }
  324. }
  325. }
  326.  
  327. int temp = scores1;
  328. scores1 = scores2;
  329. scores2 = temp;
  330. String temp1 = player1;
  331. player1 = player2;
  332. player2 = temp1;
  333.  
  334. }
  335. }
  336.  
  337. else {
  338.  
  339. System.out.println(" See you later !!!");
  340. break;
  341.  
  342. }
  343. }
  344. System.out.println(player1 + ": " + scores1);
  345. System.out.println(player2 + ": " +scores2);
  346.  
  347. if(scores1> scores2)
  348. System.out.println(player1 + " is the winner!");
  349.  
  350. else if(scores1<scores2)
  351. System.out.println(player2 +" is the winner!");
  352.  
  353. else
  354. System.out.println("The game ends in a draw");
  355.  
  356. kbReader.close();
  357. kbReader1.close();
  358. kbReader2.close();
  359. kbReader3.close();
  360.  
  361. }
  362. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement