Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. package week19;
  2.  
  3. import java.util.Random;
  4. import java.util.Scanner;
  5.  
  6. public class HigherOrLower {
  7.  
  8. public static void main(String[] args) {
  9.  
  10. Scanner scan = new Scanner (System.in);
  11. Random rand = new Random();
  12. int num1;
  13. int num2;
  14. String userInput;
  15. String userContinue;
  16. boolean exitProgram = false;
  17.  
  18. num1 = rand.nextInt(14 - 1) + 1;
  19. num2 = rand.nextInt(14 - 1) + 1;
  20. System.out.println("Card is " + num1);
  21.  
  22. while (exitProgram == false){
  23.  
  24. System.out.print("(H)igher or (L)ower :");
  25. userInput = scan.next();
  26. userInput = userInput.toUpperCase();
  27. while(exitProgram == false){
  28. if (userInput.equals("H") || userInput.equals("L")){
  29. exitProgram = true;
  30. }
  31. else{
  32. System.out.print("(H)igher or (L)ower :");
  33. userInput = scan.next();
  34. userInput = userInput.toUpperCase();
  35. }
  36. }
  37.  
  38. exitProgram = false;
  39.  
  40. if (num1 < num2 && userInput.equals("H")){
  41. System.out.println("Card is " + num2);
  42. num1 = num2;
  43. num2 = rand.nextInt(14-1) + 1;
  44. }
  45. else if (num1 > num2 && userInput.equals("L")){
  46. System.out.println("Card is " + num2);
  47. num1 = num2;
  48. num2 = rand.nextInt(14-1) + 1;
  49. }
  50. else if (num1 == num2 && (userInput.equals("L") || userInput.equals("H"))){
  51. System.out.println("Card is " + num2);
  52. num1 = num2;
  53. num2 = rand.nextInt(14-1) + 1;
  54. }
  55. else if(num1 < num2 && userInput.equals("L")){
  56. boolean exitLoop = false;
  57.  
  58. System.out.println("Card is " + num2);
  59.  
  60. System.out.print("Card is higher if you lose - play again? Yes/No");
  61. userContinue = scan.next();
  62. userContinue = userContinue.toUpperCase();
  63. while(exitLoop == false){
  64. if (userContinue.equals("H")){
  65. exitLoop = true;
  66. exitProgram = true;
  67. }
  68. else if (userContinue.equals("Yes")){
  69. exitLoop = true;
  70. num1 = rand.nextInt(14 - 1) + 1;
  71. num2 = rand.nextInt(14 - 1) + 1;
  72. System.out.println("Card is..." + num1);
  73. }else{
  74. System.out.println("Card is lower you lose - play again? Y/N");
  75. userContinue = scan.next();
  76. userContinue = userContinue.toUpperCase();
  77. }
  78. }
  79. }
  80.  
  81. else{
  82. boolean exitLoop = false;
  83.  
  84. System.out.println("Card is" + num2);
  85.  
  86. System.out.println("Card is lower you lose - play again? Y/N?");
  87. userContinue = scan.next();
  88. userContinue = userContinue.toUpperCase();
  89. while(exitLoop == false){
  90. if (userContinue.equals("N")){
  91. exitLoop = true;
  92. exitProgram = true;
  93. }
  94. else if (userContinue.equals("Y")){
  95. exitLoop = true;
  96. num1 = rand.nextInt(14 - 1) + 1;
  97. num2 = rand.nextInt(14 - 1) + 1;
  98. System.out.println("Card is " + num1);
  99. }else{
  100. System.out.print("Card is lower you lose - play again Y/N?");
  101. userContinue = scan.next();
  102. userContinue = userContinue.toUpperCase();
  103. }
  104. }
  105. }
  106. }
  107. System.out.println("Thank you for playing.");
  108. scan.close();
  109.  
  110. }
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement