473,379 Members | 1,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 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 7294
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

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

Similar topics

by: Alex Vinokur | last post by:
C++ Simulator of a Universal Turing Machine can be downloaded at : * http://alexvn.freeservers.com/s1/utm.html * http://sourceforge.net/projects/turing-machine/ The program simulates a...
by: Gandu | last post by:
I apologize if this is not the appropriate newsgroup to post this message. Could someone please tell me a good place to get an an Aloha protocol simulator source code(C++) that is well-documented...
by: Killingkids | last post by:
hello, everyone...im facing a big problem in my final year project, hope that u all can help me solve the problem ... i was doing a mobile web application which enable student to check the college...
by: Killingkids | last post by:
hello, everyone...im facing a big problem in my final year project, hope that u all can help me solve the problem ... i was doing a mobile web application which enable student to check the college...
by: lane straatman | last post by:
I'm trying to figure out what data type is appropriate to represent a card in a game. The idea that I thought was going to work was a struct, foo, with two integer fields and two fields of char...
by: Simon Biber | last post by:
I was reading http://en.wikipedia.org/wiki/Poker_probability which has a good description of how to count the frequency of different types of poker hands using a mathematical approach. A sample...
by: DanielJohnson | last post by:
I was wondering if anyblody can suggest me a network simulator written in python in which I can add on my own code and extend its functionality. I am looking for a simulator which will simualte...
by: activearun.83 | last post by:
Hi everyone, Can anyone give some idea about developing an 8085 simulator program in C? What techniques can be handled to develop this?
by: teejayem | last post by:
I am looking for some help! I am currently developing a new game for an online community. The game is called Pokino which ishalf bingo and half poker. Wierd eh?! Anyway... The final part...
by: tumundoya | last post by:
in my site: when I go with mouseover on the poker image on the poker page all the DIVS below dissapear. What am I doing wrong? Click on the poker image to go to the poker page and then hover over...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.