Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- import java.util.Random;
- import java.util.Scanner;
- public class Chap5prob21_slotMACHINEsimulation {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Random slots = new Random();
- double rollNum[] = new double[4];
- Scanner input = new Scanner(System.in);
- Scanner play = new Scanner(System.in);
- String question = "";
- double money = 0.0;
- DecimalFormat currency = new DecimalFormat("$###,###,##0.00");
- System.out.println("How much money would you like to enter?");
- money = input.nextDouble();
- do {
- System.out.println("\t");
- for(int i = 1; i<=3; i++) {
- int roll = slots.nextInt(6);
- rollNum[i] = roll++;
- if(roll == 1) {
- System.out.print("Cherries ");
- }
- else if(roll == 2) {
- System.out.print("Oranges ");
- }
- else if(roll == 3) {
- System.out.print("Plums ");
- }
- else if(roll == 4) {
- System.out.print("Bells ");
- }
- else if(roll == 5) {
- System.out.print("Melons ");
- }
- else if(roll == 6) {
- System.out.print("Bars ");
- }
- }
- if(rollNum[1] == rollNum[2] && rollNum[2] == rollNum[3]) {
- System.out.println("\n\nYou have won triple what you entered!");
- money = money * 3.0;
- }
- else if(rollNum[1] == rollNum[2] || rollNum[2] == rollNum[3] || rollNum[1] == rollNum[3]) {
- System.out.println("\n\nYou have won double what you entered!");
- money = money * 2.0;
- }
- else {
- System.out.println("\n\nYou have won nothing...");
- money -= money;
- break;
- }
- System.out.println("\nWould you like to play again betting all money won? Yes or No");
- question = play.nextLine();
- }
- while(question.equalsIgnoreCase("yes") || question.equalsIgnoreCase("y"));
- System.out.println("\nThanks for playing, you won " + currency.format(money) + "!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement