I need help with a poker simulator.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Leroymetzker
    New Member
    • Sep 2009
    • 3

    #1

    I need help with a poker simulator.

    Code:
    //My card class
    import java.util.Arrays;
    import java.util.Random;
    
    public class Card
    {
     //Attributes
      private int suit;
      private int value;
    
     //Constructors
      //Default
       public Card()
       {
        suit=0;
        value=0;
       }
    
      //Explicit
        public Card(int suit, int value)
        {
         this.suit=suit;
         this.value=value;
        }
    
           if(suit == 0)
             {
              return ("heart");
             }
    
           else if(suit == 1)
            {
             return ("spade");
            }
    
           else if(suit == 2)
            {
             return ("club");
            }
    
           else if(suit == 3)
            {
             return ("diamond");
            }
    
    
      public int getSuit()
      {
       return suit;
      }
    
      public int getValue()
      {
       return value;
      }
    
    
     public String toString()
     {
      return (suit+ "," +value);
     }
    }
    
    //My deck class
    import java.util.Arrays;
    import java.util.Random;
    
    public class Deck
    {
     public static void main(String[] args)
     {
      int[] s=new int[4];
      int[] v=new int[13];
      Card[] c=new Card[13];
      
      Random gen=new Random();
    
    
      for(int i=0; i<13; i++)
         c[i]=new Card(gen.nextInt(13), gen.nextInt(4));
      for(int i=0; i<5; i++)
       System.out.println(c[i]);
     }
    }
    Last edited by Frinavale; Sep 21 '09, 02:03 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Please use code tags if you have to post code.
    What is your question?

    Comment

    • Leroymetzker
      New Member
      • Sep 2009
      • 3

      #3
      Poker Simulator. Implement a simulation of a popular casino game called video poker. The card deck contains 52 cards, 13 of each suit/ At the beginning of the game, the deck is shuffled. The top of the 5 cards are presented to the player. The player can reject none, some, or all of the cards. The rejected cards are replaced from the top of the deck. Now the hand is scored. Your program should pronounce it to be one of the following....No pair, one pair, two...up to Royal Flush. Now, you are required to use an array to hold your deck of the cards. Because each of your cards belongs to one of the four suits and has a value, you need a Card class that has two attributes. Your Card class is required to implement the Comparable interface so that the static sort method in the Arrays class can be used to sort an array of Cards to ascending order. How to shuffle a deck? Use a random generator to generate your 52 cards: use your generator to generate a number between 0 and 4 first for the suit, then generate a number between 1(inclusive) and 13(inclusive) for the value, and then store your Card in your array. How do you evaluate a hand? Order the hand by using the static sort method from the arrays class first and then make the comparison from highest hand(royal flush) to the lowest hand(no pair)...
      Shuffle your cards, pick the first five to display, ask the player which cards of the five should be discarded, discard the cards, pick the same number of the cards from the top of the deck, evaluate and report the rank of the hand.

      Comment

      • Leroymetzker
        New Member
        • Sep 2009
        • 3

        #4
        The question is how do I move on from there to complete the program.

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          I don't even think that the code you posted will compile. You have an if/elseif/else block outside of a method.

          Anyways, you have a card class, and a deck class.


          Now you need to write a Main program that will use the Deck Class to deal out Hands of cards.

          So I would think that you would need to either create another class (Hand) or use arrays (as suggested).

          Hands would probably be the better way from an OOP point of view.

          It really helps me to understand what to do if I write down what is done step by step.

          For example, the program starts:
          • The system shuffles the deck
          • The system deals out 5 cards to 5 hands
          • Each player decides what cards to discard
          • The system starts with player 1 and asks for the cards they wish to return
          • The player returns the cards
          • The system gives them back the same amount of cards that they returned by selecting off the top of the deck
          • Each hand is evaluated to determine which hand wins.


          Each noun (I underlined some of them) is a class and each verb (I italicized some of them) is a task that the class has to do. These tasks are the methods that you have to implement...the steps that occur is the "main" application method.

          This technique is very helpful and should aid you in figure out what to do.


          The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

          Comment

          Working...