471,853 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,853 software developers and data experts.

I need help with a poker simulator.

Expand|Select|Wrap|Line Numbers
  1. //My card class
  2. import java.util.Arrays;
  3. import java.util.Random;
  5. public class Card
  6. {
  7.  //Attributes
  8.   private int suit;
  9.   private int value;
  11.  //Constructors
  12.   //Default
  13.    public Card()
  14.    {
  15.     suit=0;
  16.     value=0;
  17.    }
  19.   //Explicit
  20.     public Card(int suit, int value)
  21.     {
  22.      this.suit=suit;
  23.      this.value=value;
  24.     }
  26.        if(suit == 0)
  27.          {
  28.           return ("heart");
  29.          }
  31.        else if(suit == 1)
  32.         {
  33.          return ("spade");
  34.         }
  36.        else if(suit == 2)
  37.         {
  38.          return ("club");
  39.         }
  41.        else if(suit == 3)
  42.         {
  43.          return ("diamond");
  44.         }
  47.   public int getSuit()
  48.   {
  49.    return suit;
  50.   }
  52.   public int getValue()
  53.   {
  54.    return value;
  55.   }
  58.  public String toString()
  59.  {
  60.   return (suit+ "," +value);
  61.  }
  62. }
  64. //My deck class
  65. import java.util.Arrays;
  66. import java.util.Random;
  68. public class Deck
  69. {
  70.  public static void main(String[] args)
  71.  {
  72.   int[] s=new int[4];
  73.   int[] v=new int[13];
  74.   Card[] c=new Card[13];
  76.   Random gen=new Random();
  79.   for(int i=0; i<13; i++)
  80.      c[i]=new Card(gen.nextInt(13), gen.nextInt(4));
  81.   for(int i=0; i<5; i++)
  82.    System.out.println(c[i]);
  83.  }
  84. }
Sep 17 '09 #1
4 7148
13,262 8TB
Please use code tags if you have to post code.
What is your question?
Sep 18 '09 #2
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.
Sep 18 '09 #3
The question is how do I move on from there to complete the program.
Sep 18 '09 #4
9,735 Expert Mod 8TB
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.
Sep 21 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Alex Vinokur | last post: by
13 posts views Thread by lane straatman | last post: by
27 posts views Thread by Simon Biber | last post: by
3 posts views Thread by DanielJohnson | last post: by
18 posts views Thread by activearun.83 | last post: by
9 posts views Thread by teejayem | last post: by
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.