How to make a deck of cards in 2D array

Yes you have told me to use enums but my teacher JUST told me I'd fail if i did enums. she wnats me to do it in a 2d array
Ryan Reese
This is like a poker simulation. Won't make it a GUI yet =/
Started December 8th, 2008
//Importing a crap load of stuff to make this work
import java.util.Scanner;
import java.util.Random;
//Start the public class
public class Poker
     //deck[suit][rank]
     public static String[][] deck={{"CLUBS","DIAMONDS","SPADES","HEARTS"},{"TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE","TEN","JACK","QUEEN","KING","ACE"}};
     //start the main method
     public static void main(String args[])
          //Initialize a variable representing poker. I can call methods and such now.
          Poker poker=new Poker();
          //Make it so i can read user input
          Scanner input=new Scanner(System.in);
          //Random generator
          Random generator=new Random();
          //Welcome the user and such.
          System.out.println("Welcome to Poker!");
          //Make the 5 cards
          String card1=deal(generator.nextInt(4),generator.nextInt(12));
          String card2=deal(generator.nextInt(4),generator.nextInt(12));
          String card3=deal(generator.nextInt(4),generator.nextInt(12));
          String card4=deal(generator.nextInt(4),generator.nextInt(12));
          String card5=deal(generator.nextInt(4),generator.nextInt(12));
          //Redeal 5 cards. May not be needed
          String card6=deal(generator.nextInt(4),generator.nextInt(12));
          String card7=deal(generator.nextInt(4),generator.nextInt(12));
          String card8=deal(generator.nextInt(4),generator.nextInt(12));
          String card9=deal(generator.nextInt(4),generator.nextInt(12));
          String card10=deal(generator.nextInt(4),generator.nextInt(12));
          System.out.println("Here are your 5 starting hands\n");
          //Print out original 5 cards
          System.out.println("1)"+card1);
          System.out.println("2)"+card2);
          System.out.println("3)"+card3);
          System.out.println("4)"+card4);
          System.out.println("5)"+card5);
          //See which cards the user hates.
          System.out.println("Would you like to keep card one/two/three/four/five?");
          //Keep track of which they want to keep
          boolean keepCard1=input.nextBoolean();
          boolean keepCard2=input.nextBoolean();
          boolean keepCard3=input.nextBoolean();
          boolean keepCard4=input.nextBoolean();
          boolean keepCard5=input.nextBoolean();
          //If they dont want to keep card 1..then redeal
          //So on and so forth
          if(!keepCard1)
               card1=card6;
          if(!keepCard2)
               card2=card7;
          if(!keepCard3)
               card3=card8;
          if(!keepCard4)
               card4=card9;
          if(!keepCard5)
               card5=card10;
          //Print out the original 5 cards.
          System.out.println("1)"+card1);
          System.out.println("2)"+card2);
          System.out.println("3)"+card3);
          System.out.println("4)"+card4);
          System.out.println("5)"+card5);
          //Give user the new cards
          System.out.println("Here are your (new) 5 cards");
          System.out.println("1)"+card1);
          System.out.println("2)"+card2);
          System.out.println("3)"+card3);
          System.out.println("4)"+card4);
          System.out.println("5)"+card5);
          //Determine what kind of hand the user has.
          String hand=poker.determineHand(card1,card2,card3,card4,card5);
          System.out.println(hand);
          //Exit the program
          System.exit(0);
     public static String deal(int suit,int rank)
          String card="";
          //Making the deck out of the 2D array
          for(int i=0;i<suit;i++)
               for(int n=0;n<rank;n++)
          return card;
     public static String determineHand(String card1,String card2,String card3,String card4,String card5)
          //Some awesome crap here to determine what kind of hand the user has
          String hand="You have a ";
          //If it is a flush
          return hand;
}Inside those two for loops, what exactly should i do? I'm thinking have an array cards[][] and in each position like cards[0][0]//that is 2 of clubs
that sound right or something? Then impliment something to shuffle?

This is probably how you would've done it 10 years ago...
Ryan Reese
This is like a poker simulation. Won't make it a GUI yet =/
Started December 8th, 2008
//Importing a crap load of stuff to make this work
import java.util.Scanner;
import java.util.Random;
//Start the public class
public class Poker
     //deck[suit][rank]
     public static String suits[]={"CLUBS","DIAMONDS","SPADES","HEARTS"}, ranks[]={"TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE","TEN","JACK","QUEEN","KING","ACE"};
     //start the main method
     public static void main(String args[])
          //Initialize a variable representing poker. I can call methods and such now.
          Poker poker=new Poker();
          //Make it so i can read user input
          Scanner input=new Scanner(System.in);
          //Random generator
          Random generator=new Random();
          //Welcome the user and such.
          System.out.println("Welcome to Poker!");          
                String cards[]=new String[5],morecards[]=new String[5];
          // Initialize the deck
                int deck[][]=new int[13][4];
                for(int i=0;i<13;i++)for(int j=0;j<4;j++)deck[i][j]=-1;
                //Make the 5 cards
                for(int i=0;i<5;i++){
                       int suit=generator.nextInt(4),rank=generator.nextInt(13);
                       while(deck[rank][suit]!=-1){
                              suit=generator.nextInt(4);rank=generator.nextInt(13);
                       cards=rank*4+suit;
deck[rank][suit]=-1;
          //Redeal 5 cards. May not be needed          
for(int i=0;i<5;i++){
int suit=generator.nextInt(4),rank=generator.nextInt(13);
while(deck[rank][suit]!=-1){
suit=generator.nextInt(4);rank=generator.nextInt(13);
morecards[i]=rank*4+suit;
deck[rank][suit]=-1;
          System.out.println("Here are your 5 starting hands\n");
          //Print out original 5 cards
          for(int i=0;i<5;i++)System.out.println((i+1)+")"+ranks[cards[i]/4]+" "+suits[cards[i]%4]);
          //See which cards the user hates.
          System.out.println("Would you like to keep card one/two/three/four/five?");
          //Keep track of which they want to keep
boolean keepCard[]=new boolean[5];
for(int i=0;i<5;i++)keepCard[i]=input.nextBoolean();
          //If they dont want to keep card 1..then redeal
          //So on and so forth
for(int i=0;i<5;i++)if(keepCard[i]==false)cards[i]=morecards[i+5];
          //Print out the original 5 cards.
          for(int i=0;i<5;i++)System.out.println((i+1)+")"+ranks[cards[i]/4]+" "+suits[cards[i]%4]);
          //Give user the new cards
          System.out.println("Here are your (new) 5 cards");
          for(int i=0;i<5;i++)System.out.println((i+1)+")"+ranks[cards[i]/4]+" "+suits[cards[i]%4]);
          //Determine what kind of hand the user has.
          String hand=poker.determineHand(card1,card2,card3,card4,card5);
          System.out.println(hand);
          //Exit the program
          System.exit(0);
     public static String determineHand(String card1,String card2,String card3,String card4,String card5)
          //Some awesome crap here to determine what kind of hand the user has
          String hand="You have a ";
          //If it is a flush
          return hand;
...Happy holidays...

Similar Messages

  • How to export key in smart card to byte array?

    How to export key in smart card to byte array?
    I want to export key to byte array to xor with some data. How can I do?
    I use java card kit 1.2.1 and jdk1.3.1_02
    Thanks

    Can I write like this?
    import javacard.security.*;
    /* in method */
    byte[] keyExoprt = new byte[64];
    Key v = Key.buildKey(KeyBuilder.TYPE_DSA_PRIVATE,KeyBuilder. LENGTH_DSA_512, false);
    short a = DSAPrivateKey.getX(keyExport, KeyBuilder. LENGTH_DSA_512);
    ////////////////////////////////////////////////////////////////////////////////////////

  • How to make a graph inside a while loop maintain previous values

    In the beginning I was trying to use an the XY Graph Express VI to create a plot of points.  However, the graph is making a linear retrace between the first point of the new line, and the last point of the previous line.  It then creates the new line as desired.
    I have tried using a for loop with to bundle a cluster to the graph, but the graph resets the plot on each iteration (as expected) and I cannot find a way to make it maintain the previous data.  I tried using shift registers but was unable to find out how to do this, and I have also tried bundling the cluster to an array, but cannot figure out how to make the cluster go to a 1D array of a cluster of 2 elements.
    One option is having is finding a way to make it maintain previous data, but the preferred option is to make it create a new plot on each iteration so as to see the color change for each new plot.
    Solved!
    Go to Solution.
    Attachments:
    shift register attempt.JPG ‏64 KB
    original attempt.JPG ‏42 KB
    Output only current iteration data.JPG ‏86 KB

    I'm taking a stab at this because I'm not exactly sure what you want. But I think it is what I have shown here. You need to use a shift register on your outter while loop as I have shown. Your image where you tried using a shift register shows a misunderstanding of shift registers and how they work though, so I would take a look at these tutorials.
    CLA, LabVIEW Versions 2010-2013
    Attachments:
    plot with SR.png ‏29 KB

  • How to make a Bose sound deck access iTunes?

    I am a real novice and this one is a bit around the houses, but I'd be grateful for any insight anyone can give me!
    I bought a Mac Pro dual core about 3 years ago now.  At the time I requested an Airport card, but when I got it home, it was not installed.  My router ended up being right next to the computer so I connected by ethernet and forgot about it.
    We moved quite recently and this became an issue.  The wireless router is on the ground floor and the desktop, in the loft conversion!  I explored retro fitting an Airport card, but I was told it was difficult and expensive (should have got the apple store to sort it out originally...).  Anyway I ended up using a Netgear wireless extender, on the middle floor to boost the Virgin wireless router, with an Airlink dongle in the Mac's USB port, to get the internet in the loft.
    This works fine (most of the time...).  BUT and heres the issue today.  My husband just bought a Bose Sound deck 10, which is on the ground floor.  He wants to be able to play his music from iTunes (which is in the loft).  He has today bought an Airport Express, thinking this was going to link up nicely.  I can see how it could with the airport card, which we don't have.  However it does seem that we should be able to make Airplay work, but the Mac can't see the Airport Express.  Can I somehow use my extended wireless network of Netscape extender and Airlink dongle, to make this work???  I can't seem to find a way to access it.
    Or can anyone suggest a better way to do this?  Not sure if its relevant, but he has downloaded Remote from the app store to his iPad, to enable him to play his (vast) music collection on the Bose.  the iPad can see his iTunes account from downstairs - so that distance doesn't seem a problem.  Just back to the issue of how to get that music to play through the Bose.
    I hope this makes sense.  I am 8 months pregnant, so not a lot does right now to be fair.  He's in a bit of a grump about it and I know if I don't sort it now...!!!
    Thanks in advance.

    If iTunes doesn't recognize a set of iOS device backup folders as valid then the chances of rescuing any data from them are slim. There are various iOS device backup extraction tools that may or may not do something useful, I've not had reason to test them.
    If you want to backup your iTunes library (and you should) see this user tip.
    tt2

  • I have a $10 gift card balance on my Apple ID but when I try to rent a movie it wants me to use my debit card. How can Make it use the iTunes credit?

    I have a $10 gift card balance on my Apple ID but when I try to rent a movie it wants me to use my debit card. How can Make it use the iTunes credit?

    Hi ...
    Select None for payment method > iTunes Store: Changing account information
    Be aware, an auto renewing subsciption by require a credit card.

  • My kids have their own AppleIDs but have entered my credit card info to make purchases from their own devices. How do I remove my credit card information to prevent them charging to my card?

    My kids have their own AppleIDs but have entered my credit card info to make purchases from their own devices. How do I remove my credit card information to prevent them charging to my card?

    Hi Sconnor_USA,
    You may be able to select None as a payment method, rather than having a credit card on their accounts with this article:
    Change or remove your payment information from your iTunes Store account (Apple ID)
    If you cannot select none, this article should provide more information on why:
    Why can’t I select None when I edit my Apple ID payment information?
    Thank you for using Apple Support Communities.
    All the very best,
    Sterling

  • Hey guyz can u help me out on how to make an apple ID on iPhone 4s without having a credit card information

    Hey guyz can u help me out on how to make an apple ID on iPhone 4s without having a credit card information

    http://support.apple.com/kb/ht2534

  • HT201209 How do I use iTunes gift card to make in app purchases

    How do I use iTunes gift card to make in app purchases?

    Itunes verifies your account using credit card info.

  • How do I get the 1121 card to read the switch and make it a 1 or 0 to count pulses?

    Hello,
    I am developing a test stand to test tires. We have LabView 7.1 and the SCXI chassis with an 1121 transducer card. I am trying to count the rate and total number of revolutions made by the tire. The signal is acquired from a 12V-proximity switch that is actuated once per RPM. The tire turns at 1,000 RPM or a little more.
    The signal will have to go through a 100-foot cable to get to the LabView chassis, will this be a problem?
    How do I get the 1121 card to read the switch and make it a 1 or 0 to count pulses?
    Will LabView be able to read this many pulses per second?
    How do I get MPH and a RPM reading out of it?
    Thank you,
    James Happe

    Hi James,
    Since you are cabling your DAQ board to an SCXI chassis with an 1121, you will not be able to use your counters without additional hardware.
    The 1121 is an analog input signal conditioning module. It performs filtering and attenuation to help measure analog signals. What it does not have is access to your board's counter pins.
    In order to use your counter pins you will need to get the necessary hardware. You have two options:
    1) Buy and SCB-68. This is a breakout box that will cable directly to your DAQ board replacing your SCXI chassis. You can connect your signals directly to your counter with this. However, I would advise against this because your application has a 12 volt signal. This will overload the 5v maximum voltage for your counter pins.
    2) Buy a 1180 feedthrough panel. This will allow you to use all of your DAQ board's functions with the SCXI chassis. Withouth the 1180 feedthrough panel, the SCXI-1121 is the only thing connected to your DAQ board. Since the 1121 only performs conditioning on the analog inputs, that is all you can access. The other pins cannot be used (no access). With the 1180 feedthrough panel, you can put a connector block on and access all of your other pins (including the counter pins). Again, I would advise against this since your 12 volt signal will overload your counter pins.
    My suggestion would be to perform an analog input task. Set up your 1121 in MAX and use a LabVIEW shipping example. In the shipping example select an analog input channel from your SCXI-1121 module. Set the appropriate voltage range and take some measurements. Once your signal is connected and you can read it using an analog input example you are half way there.
    Take the analog input shipping example and modify it to perform frequency analysis on the voltage readings. You can simply wire the data from the DAQmxRead VI into one of the frequency analysis VI's (noted in my first post). The output if that VI will give you the frequency of your signal.
    -Sal

  • Today my money is deducted Rs.60 when I try to download paid applications of any amount and I am getting message transaction declined, so why my money is deducted. I lost almost Rs 480 rupees . So how to get refund and how to make card working?

    Today my money is deducted Rs.60 when I try to download paid applications of any amount and I am getting message transaction declined, so why my money is deducted. I lost almost Rs 480 rupees . So how to get refund and how to make card working?

    Today my money is deducted Rs.60 when I try to download paid applications of any amount and I am getting message transaction declined, so why my money is deducted. I lost almost Rs 480 rupees . So how to get refund and how to make card working?

  • I have 3G sim card how to make reugular call in ipad air 4G. tell me.

    i have 3G sim Card how to make regular call in ipad iar 4G. tell me.

    You have to use an app such as Skype or Viber. iPad has no
    telephone capability as sim is data only.

  • TS1292 i got an itune card after I hit the pin in it show invalid number, so how to make it work?

    I got an itune card after I hit the pin in, it show invalid number so how to make it work?

    See Here  >  iTunes Store: Invalid, inactive, or illegible codes
    http://support.apple.com/kb/TS1292

  • I am From Asia, Malaysia. I'm still was a student, I would like to purchase a Macbook at online With Student price. How I make the payment at online?? Am I able to used my dad's credit card?

    I am From Asia, Malaysia. I'm still was a student, I would like to purchase a Macbook at online with student price. How I make the payment at online?? Am I able to used my dad's credit card? or any proof?? Emergency ***

    http://store.apple.com/my/browse/home/education_routing
    If you have further questions about the policies and procedures for ordering, call the Malaysian Apple Store at 1800-80-6419. Everyone here is just a fellow user and cannot speak for Apple.
    Regards.

  • How to make a Christmas card?

    I... just... don't know how to make a good card. Can you help, please?

    Try
    http://discussions.apple.com/thread.jspa?threadID=2258847&tstart=0
    You can look at examples already created and copy or modify them.
    Only you can decide what you think is good however.
    Peter

  • Can someone help me in learning how to make business cards using pages

    can someone please help me in learning how to make business cards using pages

    You could jump start the process with an Avery MS Word 8-up business card template as a free download. Either version of Pages will digest it nicely. Once you load it into Pages, do a File > Save As Template.. , add it to Chooser, and give it your name choice. Both versions of Pages will remove the printer registration marks in all four template corners. The free LibreOffice Writer retains them.

Maybe you are looking for

  • Is there any way to contact customer support without having to pay for this service?

    I'm having trouble installing the latest update of the OS on my MacBook Pro, and after trying a couple of things, I just wanted to get in touch with a customer service representative to help me out with the issue.  Turns out that my "support coverage

  • .wid file opens for some developers Web Intell Rich Client but not others

    4 developers with same BO client installs @ 12.2.7.598** (server at 3.2 SP 2.7) 2 can read demo .wid files and 3rd party supplied .wid file, 2 cannot!* Error produced when running: An internal error occured while calling 'openDocumentMDP' API. (Error

  • Screen of Zen Stone Plus with pixel problem

    +I have a problem with the screen: seems that some colums of the screen does not work properly. [url="http://imageshack.us/photo/my-images/863/img0955k.jpg/" target="_blank" title="ImageShack - Image And Video Hosting"><img border="0" src="http://img

  • WebLogic 11g EAR EJB Classpath and class loaders

    All, I have been having issues migrating Spring based EJB applications from OC4J to WebLogic 11g (10.3.1). I have been in communication with Oracle who has suggested a work around however I am keen to see if anyone else can suggest a solution. The ap

  • Not recieving emails to verify email address for sync (2nd request)

    Anybody out there can help me? Please not getting verification email I am unable to get verification emails for sync. I check security and Mozilla Firefox is allowed. I have the latest version and I need help. I want sync to migrate my Firefox bookma