Advertisement
tjb1

Untitled

Nov 24th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Random;
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class Chap5prob21_slotMACHINEsimulation {
  7.  
  8. /**
  9. * @param args
  10. */
  11. public static void main(String[] args) {
  12. // TODO Auto-generated method stub
  13. Random slots = new Random();
  14. double rollNum[] = new double[4];
  15. Scanner input = new Scanner(System.in);
  16. Scanner play = new Scanner(System.in);
  17. String question = "";
  18. double money = 0.0;
  19. DecimalFormat currency = new DecimalFormat("$###,###,##0.00");
  20.  
  21. System.out.println("How much money would you like to enter?");
  22. money = input.nextDouble();
  23.  
  24. do {
  25. System.out.println("\t");
  26. for(int i = 1; i<=3; i++) {
  27. int roll = slots.nextInt(6);
  28. rollNum[i] = roll++;
  29.  
  30.  
  31. if(roll == 1) {
  32. System.out.print("Cherries ");
  33. }
  34. else if(roll == 2) {
  35. System.out.print("Oranges ");
  36. }
  37. else if(roll == 3) {
  38. System.out.print("Plums ");
  39. }
  40. else if(roll == 4) {
  41. System.out.print("Bells ");
  42. }
  43. else if(roll == 5) {
  44. System.out.print("Melons ");
  45. }
  46. else if(roll == 6) {
  47. System.out.print("Bars ");
  48. }
  49.  
  50. }
  51.  
  52. if(rollNum[1] == rollNum[2] && rollNum[2] == rollNum[3]) {
  53. System.out.println("\n\nYou have won triple what you entered!");
  54. money = money * 3.0;
  55. }
  56. else if(rollNum[1] == rollNum[2] || rollNum[2] == rollNum[3] || rollNum[1] == rollNum[3]) {
  57. System.out.println("\n\nYou have won double what you entered!");
  58. money = money * 2.0;
  59. }
  60. else {
  61. System.out.println("\n\nYou have won nothing...");
  62. money -= money;
  63. break;
  64. }
  65.  
  66. System.out.println("\nWould you like to play again betting all money won? Yes or No");
  67. question = play.nextLine();
  68.  
  69. }
  70. while(question.equalsIgnoreCase("yes") || question.equalsIgnoreCase("y"));
  71.  
  72. System.out.println("\nThanks for playing, you won " + currency.format(money) + "!");
  73. }
  74.  
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement