Monty374

High Low Game

Oct 18th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. package ex8;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6. *
  7. * @author Monty
  8. */
  9. public class Ex8 {
  10.  
  11. /**
  12. * @param args the command line arguments
  13. */
  14. public static void main(String[] args) {
  15. Scanner input = new Scanner(System.in);
  16. int guess, points, random, bet, round;
  17. double rand;
  18. points = 1000;
  19.  
  20. rand = (13 - 1 + 1) * Math.random() + 1;
  21. random = (int)rand;
  22. bet = 0;
  23. guess = 0;
  24. round = 1;
  25.  
  26. intro();
  27. while (points > 0) {
  28. play(bet, random, points, guess);
  29. round +=1;
  30. }
  31.  
  32. System.out.print("Times gussed: " + round);
  33.  
  34.  
  35. }
  36.  
  37. public static void intro() {
  38. System.out.print("High Low Game\n");
  39. System.out.print("RULES:\n");
  40. System.out.print("Numbers 1-6 are low\n");
  41. System.out.print("Number 8-13 are high\n");
  42. System.out.print("Number 7 is neither\n\n");
  43. System.out.print("You have 1000 points.\n ");
  44. }
  45.  
  46. public static int play(int bet, int random, int points, int guess) {
  47. Scanner input = new Scanner(System.in);
  48. String answer;
  49. System.out.print("\nEnter points to risk: ");
  50. bet = input.nextInt();
  51. System.out.print("\nPredict (1=high, 0=low): ");
  52. guess = input.nextInt();
  53. System.out.print("\nNumber is: " + random);
  54. if (random <= 6 && guess == 0 || random >= 8 && guess == 1) {
  55. System.out.print("\nYou win!");
  56. points = 2*bet + points;
  57. System.out.print("\n\nYou have " + points + " points.");
  58. } else {
  59. System.out.print("\nYou lose.");
  60. points = points - bet;
  61. System.out.print("\n\nYou have " + points + " points.");
  62. }
  63. if ( points <= 0) {
  64. System.out.print("\nPlay again? (y/n): ");
  65. answer = input.nextLine();
  66. if (answer.equalsIgnoreCase("y")) {
  67. System.out.print("\n\nYou have " + points + " points.\n");
  68.  
  69. } else if (answer.equalsIgnoreCase("n")) {
  70. points = 0;
  71. }
  72. }
  73. return (points);
  74.  
  75. }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment