Guest User

Untitled

a guest
Jan 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class ChuckALuck {
  4.  
  5. public static void main (String[] args) {
  6. Scanner s = new Scanner(System.in);
  7. double bankRoll = bankRoll(s);
  8. int i = 1;
  9. while(i==1) {
  10. bankRoll = gamePlay(s, bankRoll);
  11. i = gameEnd(i, bankRoll, s);
  12. }
  13. }
  14.  
  15. public static double bankRoll(Scanner s) {
  16. System.out.println("How much do you want to add to your bankroll?");
  17. System.out.println("(Please use a decimal value)");
  18. double bankRoll = s.nextDouble();
  19. return bankRoll;
  20. }
  21.  
  22. public static double gamePlay(Scanner s, double br) {
  23. int i = 0;
  24. double betValue =0;
  25. while(i==0) {
  26. System.out.println("What is the value of your next bet ($0.00 - $" + br + ")?");
  27. betValue = s.nextDouble();
  28. br = br - betValue;
  29.  
  30. // ensures a correct bet value is chosen
  31. if (betValue <= br) {
  32. i = 1;
  33. }
  34. else {
  35. System.out.println("You cannot bet more than what is in your bankroll. Try again.");
  36. }
  37. }
  38. // Takes the bet number
  39. int betNumber = 0;
  40. while(i==1) {
  41. System.out.println("Choose a number between 1 and 6:");
  42. betNumber = s.nextInt();
  43. // ensures a correct dice value is chosen
  44. if ((1<=betNumber)&&(betNumber<=6)) {
  45. i = 0;
  46. }
  47. else {
  48. System.out.println("That is not a valid selection. Try again.");
  49. }
  50. }
  51. //dice rolls
  52. Random r = new Random();
  53. int rollOne = r.nextInt(6) + 1;
  54. int rollTwo = r.nextInt(6) + 1;
  55. int rollThree = r.nextInt(6) + 1;
  56. System.out.println("Dice rolls: "+rollOne+" "+rollTwo+" "+rollThree);
  57. // calculates and prints winnings
  58. int matchingDie = 0;
  59. if(betNumber == rollOne) {
  60. matchingDie++;
  61. }
  62. if(betNumber == rollTwo) {
  63. matchingDie++;
  64. }
  65. if(betNumber == rollThree) {
  66. matchingDie++;
  67. }
  68. if(matchingDie==1) {
  69. double winnings = betValue;
  70. System.out.println("Winnings = $"+ winnings);
  71. return br + winnings;
  72. }
  73. if(matchingDie==2) {
  74. double winnings = betValue*2;
  75. System.out.println("Winnings = $"+ winnings);
  76. return br + winnings;
  77. }
  78. if(matchingDie==3) {
  79. double winnings = betValue*10;
  80. System.out.println("Winnings = $"+ winnings);
  81. return br + winnings;
  82. }
  83. if(matchingDie==0) {
  84. double winnings = 0.00;
  85. System.out.println("Winnings = $"+ winnings);
  86. return br;
  87. }
  88.  
  89. }
  90.  
  91. public static int gameEnd(int gameNum, double br, Scanner s) {
  92. System.out.println("After bet "+gameNum+" your bankroll is $"+br);
  93. System.out.println();
  94. System.out.println("Do you want to keep playing?");
  95. String replay = s.nextLine();
  96. if(replay.equals("y")){
  97. return 1;
  98. }
  99. if(replay.equals("yes")){
  100. return 1;
  101. }
  102. if(replay.equals("no")){
  103. return 0;
  104. }
  105. if(replay.equals("n")){
  106. return 0;
  107. }
  108. }
  109.  
  110. }
Add Comment
Please, Sign In to add comment