Monty374

EX 8

Nov 1st, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 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.  
  55. if (random <= 6 && guess == 0 || random >= 8 && guess == 1) {
  56. System.out.print("\nYou win!");
  57. points = 2*bet + points;
  58. System.out.print("\n\nYou have " + points + " points.");
  59. } else {
  60. System.out.print("\nYou lose.");
  61. points = points - bet;
  62. System.out.print("\n\nYou have " + points + " points.");
  63. }
  64.  
  65. if ( points <= 0) {
  66. System.out.print("\nPlay again? (y/n): ");
  67. answer = input.nextLine();
  68. if (answer.equalsIgnoreCase("y")) {
  69. System.out.print("\n\nYou have " + points + " points.\n");
  70.  
  71. } else if (answer.equalsIgnoreCase("n")) {
  72. points = 0;
  73. }
  74. }
  75. return (points);
  76.  
  77. }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment