Results 1 to 6 of 6
  1. #1
    VIhuri is offline Member
    Join Date
    Nov 2012
    Posts
    12
    Rep Power
    0

    Default Need help with pokerhand/two pairs

    I need to create a program that checks whether the randomly assigned hand contains two pairs. Now this could be done with one heck of an if - method containing all the possible variations of two pairs. Another way I figured would be to sort the array and check whether any two indexes that are alongside were equal. However, I cannot use Arrays.sort.

    Now I'm at a loss on how to proceed. The for - methods I thought of that would put each member of the array against each other would also count in three of the same and four of the same.

    Any hints on how to proceed here?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Need help with pokerhand/two pairs

    Why can't you use sort()? If it's an arbitrary assignment condition, then perhaps you are meant to implement your own sort method for the array.

    Sorting would make sense, not only for detecting two pairs (remember to distinguish 2 pairs from 4 of a kind) but for doing other hand evaluations.

    ---

    Another approach would be to create an array of 13 ints. Use a for loop to go through the hand counting the card values. Then another for loop could go through the array of face value counts and see how many 2's there are.
    Last edited by pbrockway2; 12-01-2012 at 11:41 AM.

  3. #3
    VIhuri is offline Member
    Join Date
    Nov 2012
    Posts
    12
    Rep Power
    0

    Default Re: Need help with pokerhand/two pairs

    I decided to go with the one heck of an if-statement. It's clumsy as hell but works.

    Also need to work out this: I need to print out the number of the card and whether it's a club, heart etc.

    I can parse out the information of the type and turn it to integers 1-4. Is there anyway to attach a string to each of these values? So if the card's type has a value of 1, it would print out "spades"?


    edit: I cannot use sort() because this assignment is done in artificial environment. I can only type certain amount of code; the rest is given. And the it hasn't imported java.util.Arrays.

  4. #4
    VIhuri is offline Member
    Join Date
    Nov 2012
    Posts
    12
    Rep Power
    0

    Default Re: Need help with pokerhand/two pairs

    Ooooh yeah, baby! Got it working!

    Well, with the clumsy huge if-method but still.

    The second part was so easy it's embarassing. Just created a String-array.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,247
    Rep Power
    19

    Default Re: Need help with pokerhand/two pairs

    Quote Originally Posted by VIhuri View Post
    I can parse out the information of the type and turn it to integers 1-4. Is there anyway to attach a string to each of these values? So if the card's type has a value of 1, it would print out "spades"?
    Quote Originally Posted by VIhuri View Post
    The second part was so easy it's embarassing. Just created a String-array.
    Have you learned Enums yet?
    Enum Types (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    VIhuri is offline Member
    Join Date
    Nov 2012
    Posts
    12
    Rep Power
    0

    Default Re: Need help with pokerhand/two pairs

    Nope. I've encountered the word in error messages but that's about it.

    I would like to hear how the two pairs problem would have been solved in a more efficient way. The tools we've been given in this class thus far aren't exactly very refined (if, while/for, tables, subprograms)

Similar Threads

  1. Sort through array, finding pairs.
    By Wnt2bsleepin in forum New To Java
    Replies: 25
    Last Post: 02-08-2012, 03:29 AM
  2. Java-programmed card game pairs
    By Galore in forum Java Applets
    Replies: 0
    Last Post: 08-30-2009, 07:34 AM
  3. Help with creating the game pairs
    By dave141000 in forum New To Java
    Replies: 1
    Last Post: 08-15-2009, 06:25 PM
  4. Object Key value pairs
    By Anitha in forum New To Java
    Replies: 1
    Last Post: 06-13-2008, 01:25 PM
  5. Working with Key-Value Pairs in a Hashtable
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-12-2008, 08:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •