Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. int random;
  7. int playerChoice;
  8. String continueGame;
  9. Scanner scanner = new Scanner(System.in);
  10.  
  11. while(true)
  12. {
  13. System.out.println("\f");
  14. System.out.println("RULES:\nEnter an integer value between 1 and 100.\nYou have 5 tries.");
  15. int x = 1;
  16. random = (int)(Math.random() * 100) + 1;
  17. while(x <= 5)
  18. {
  19. System.out.print("Enter your guess: ");
  20. playerChoice = scanner.nextInt();
  21.  
  22. if(playerChoice < 0 || playerChoice > 100)
  23. {
  24. System.out.println("Enter a valid number 1 - 100!");
  25. }
  26. else if (playerChoice == random)
  27. {
  28. System.out.println("Winner, winner, chicken dinner!");
  29. System.out.println("You tried " + x + " times. You had " + (5 - x) + " tries left.");
  30. }
  31. else
  32. {
  33. System.out.println("Nope.");
  34. if(playerChoice > random)
  35. {
  36. System.out.println("Your guess was too high :)");
  37. System.out.println("Guesses left: " + (5 - x ));
  38. } else if (playerChoice < random)
  39. {
  40. System.out.println("Your guess was too low! :(");
  41. System.out.println("Guesses left: " + (5 - x ));
  42. }
  43.  
  44. x++;
  45.  
  46. if(x > 5)
  47. {
  48. System.out.println("You have used all your tries. The number was " + random);
  49. }
  50. }
  51. }
  52.  
  53. System.out.println("Continue? [Y/N]");
  54. continueGame = scanner.next().trim();
  55. if (continueGame.toLowerCase().equals("n"))
  56. {
  57. break;
  58. }
  59. } // END OF while LOOP
  60.  
  61. } // END OF main METHOD
  62.  
  63. } // END OF Main CLASS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement