Guest User

Untitled

a guest
Apr 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.71 KB | None | 0 0
  1. public static void main(String[] args) {
  2. Scanner input = new Scanner(System.in);
  3. boolean UserCheck = true;
  4. String respond = "Y" ;
  5. int respondCount = 0 ;
  6.  
  7. int[] randomCheckA = new int[150];
  8. int[] randomCheckB = new int[150];
  9. int[] randomCheckC = new int[150];
  10. int countrandomA = 0;
  11. int countrandomB = 0;
  12. int countrandomC = 0;
  13.  
  14. while (UserCheck) {
  15. System.out.println("Welcome to Puzzle game");
  16. if (respondCount < 1) {
  17. System.out.println("Do you want to play press (Y) / (N)");
  18. }
  19. if (respondCount == 0) {
  20. respond = input.next();
  21. }
  22. if (respond.equals("y") || respond.equals("Y") || respondCount > 0) {
  23. Random Ran = new Random();
  24. String choice;
  25. String[] cities = new String[3];
  26. String[] animals = new String[3];
  27. String[] cars = new String[3];
  28.  
  29. System.out.println("Select a catagorie n (a)Cars n (b)Cities n (c)Animals ");
  30. String ch = input.next();
  31. char c = ch.charAt(0);
  32. switch(c) {
  33.  
  34. case 'a':
  35. if (countrandomC >= 3) {
  36. System.out.println("You have finished this catagories");
  37. break;
  38. }
  39. cars[0] = "ford";
  40. cars[1] = "nissan";
  41. cars[2] = "lexus";
  42. int random = Ran.nextInt(3);
  43. randomCheckC[random]++;
  44. while (true) {
  45.  
  46. if (randomCheckC[random] > 1) {
  47. random = Ran.nextInt(3);
  48. }//if
  49. else {
  50. randomCheckC[random]++;
  51. countrandomB++;
  52. break;
  53.  
  54. }
  55. }
  56. choice = cars[random];
  57. search(choice);
  58. break;
  59. case 'b':
  60. if (countrandomB >= 3) {
  61. System.out.println("You have finished this catagories");
  62. break;
  63. }//if
  64. animals[0] = "lion";
  65. animals[1] = "tiger";
  66. animals[2] = "cat";
  67. random = Ran.nextInt(3);
  68. randomCheckB[random]++;
  69. while (true) {
  70.  
  71. if (randomCheckB[random] > 1) {
  72. random = Ran.nextInt(3);
  73. } //if
  74. else {
  75. randomCheckB[random]++;
  76. countrandomB++;
  77. break;
  78.  
  79. }
  80. }
  81. choice = animals[random];
  82. search(choice);
  83. break;
  84.  
  85. case 'c':
  86. if (countrandomA >= 3) {
  87. System.out.println("You have finished this catagories");
  88. break;
  89. }//if
  90. cities[0] = "alquds";
  91. cities[1] = "istanbul";
  92. cities[2] = "amman";
  93. random = Ran.nextInt(3);
  94. randomCheckA[random]++;
  95. while (true) {
  96.  
  97. if (randomCheckA[random] > 1) {
  98. random = Ran.nextInt(3);
  99. }
  100. else {
  101. randomCheckA[random]++;
  102. countrandomA++;
  103. break;
  104. }
  105. }
  106. choice = cities[random];
  107. search(choice);
  108. break;
  109. default:
  110. System.out.println("Sorry your enter is not valid");
  111. break;
  112. }
  113. System.out.println("Congrats! you solved it n Do you want to play again?");
  114. String respond2 = input.next();
  115. if (!(respond2.equals("Y") || respond2.equals("y"))) {
  116. break;
  117. }
  118. respondCount++;
  119.  
  120. }//if
  121. else {
  122. break;
  123. }
  124. }//while
  125. }//main
  126.  
  127. public static String convert(String x) {
  128.  
  129. String worda = x.replaceAll(".", "-");
  130.  
  131. return worda;
  132. }
  133.  
  134. public static void search(String choice) {
  135. int Try = 0;
  136. int[] lettersCheck = new int[150];
  137. Scanner input = new Scanner(System.in);
  138. int countWord;
  139. int count = 0;
  140. int count2 = 0;
  141. countWord = choice.length();
  142. System.out.println("The number of letters in the word is :" + countWord);
  143. System.out.println(convert(choice));
  144. StringBuilder FinalAnswer = new StringBuilder();
  145. while (count < countWord) {
  146.  
  147. StringBuilder Answer = new StringBuilder();
  148. String c1 = input.next();
  149. char look = c1.charAt(0);
  150. lettersCheck[look]++;
  151. if ((choice.indexOf(look) != -1) && lettersCheck[look] <= 1) {
  152.  
  153. for (int i = 0; i < choice.length(); i++) {
  154. if (choice.charAt(i) == look) {
  155. if (count2 == 0) {
  156. Answer.append(choice.charAt(i));
  157. FinalAnswer.append(choice.charAt(i));
  158. count++;
  159. }//if
  160. else {
  161.  
  162. Answer.append(choice.charAt(i));
  163. FinalAnswer.replace(i, i + 1, "" + look);
  164. count++;
  165. }//else
  166.  
  167. }//if
  168. else {
  169. if (count2 == 0) {
  170. FinalAnswer.append('-');
  171. }//if
  172.  
  173. if (FinalAnswer.charAt(i) == '-') {
  174. Answer.append('-');
  175. } else {
  176. Answer.append(FinalAnswer.charAt(i));
  177. }
  178.  
  179. }//else if
  180.  
  181. }//for
  182. count2++;
  183. System.out.println(Answer);
  184.  
  185. }//if
  186. else {
  187. if ((choice.indexOf(look) != -1) || lettersCheck[look] > 1) {
  188. System.out.println("You have already enter this charachter");
  189. }//if
  190. else {
  191. System.out.println("The letter is wrong reenter your letter");
  192. Try++;
  193. }
  194. if (Try >= 10) {
  195. System.out.println("Sorry you lost");
  196. break;
  197. }//if
  198. }//else if
  199. }//while
  200.  
  201. }
Add Comment
Please, Sign In to add comment