jeudi 25 février 2016

Roulette using Arrays and Lists [duplicate]

This question already has an answer here:

Okay, I'm trying to make a really simple and dumbed down version of Roulette. So basically the user chooses "REd" or "BLAck" and then the system generates a random number between 1 and 36, Red contains a list of numbers as well as black if the user guess the proper color based off the randomly generated number they win. My code runs without an error so I cant seem to find out the issue, however it doesn't seem to print anything.........I think the error is in the iF and Else If statements......Any ideas??

 import java.io.*;
 import javax.swing.*;
 import java.util.List;
 import java.util.Arrays;
 import java.io.IOException;

 public class PracticeProgram {



    public static void main(String[] args)throws IOException  {
            {


                String input = JOptionPane.showInputDialog(null,"A) Red\n" + "B) Black");
                String redBlack = input;


                List<Integer> red = Arrays.asList(1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36); 

                List<Integer> black = Arrays.asList(2,4,6,8,10,11,13,15,17,19,21,23,25,27,29,31,33,35);


                int roulette=(int)(Math.floor(Math.random()*36+1));

                if (red.contains(roulette) && redBlack == "A")
                {
                    JOptionPane.showMessageDialog(null, "YOu win");
                }
                else if (red.contains(roulette) && redBlack == "B")
                {
                    JOptionPane.showMessageDialog(null, "YOu lose");
                }
                else if (black.contains(roulette) && redBlack == "A")
                {
                    JOptionPane.showMessageDialog(null, "you lose");
                }
                else if (black.contains(roulette) && redBlack == "B")
                {
                    JOptionPane.showMessageDialog(null,"You WIn");
                }
                }
        }
}

Aucun commentaire:

Enregistrer un commentaire