Guest User

Untitled

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