Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: hi I'm doing a poker game project, but I find it hard to do. Can someone please help me?

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default hi I'm doing a poker game project, but I find it hard to do. Can someone please help me?

    okay so I did the card.java
    public class Card {

    private int Value;
    private int Suit;
    /*1 - club ♣
    *2 - diamond ♦
    *3 - spade ♠
    *4 - heart ♥
    */
    String club;
    public Card()
    {
    Value=1;
    Suit = 1;
    }
    public Card(int v, int s)
    {
    Value = v;
    Suit=s;
    }
    public int getValue()
    {
    return Value;
    }
    public int getSuit()
    {
    return Suit;
    }
    public String getName()
    {
    String name = "";
    if(Value == 11)
    name += "J";
    if(Value == 12)
    name += "Q";
    if(Value == 13)
    name += "K";
    if(Value == 1)
    name += "A";
    if(Suit == 1)
    name += "C♣";
    if(Suit == 2)
    name += "D♦";
    if(Suit == 3)
    name += "S♠";
    if(Suit == 1)
    name += "H♥";
    return name;
    }
    }
    I don't know how to do the bet class, bankroll class, deck class, hand class and player class.
    But I tried to do BankRoll, deck and Bet but I don't know if these are correct. here are the codes:
    [[Here's what my teacher statement: Bet Class
    Information (variables):
    - Amount of Bet
    Actions (methods):
    - Return amount of bet
    - Change amount of bet
    ]]
    public class Bet {
    private int Bet;
    public Bet()
    {
    Bet=1;
    }
    public Bet(int b)
    {
    Bet = b;
    }
    public int getBet()
    {
    return Bet;
    }
    public void ChangeBet()
    {
    }
    [[For :Bankroll Class
    Information (variables):
    - Balance
    Actions (methods):
    - Update current number of credits (increase or decrease), can be set
    - Return the number of credits
    - Change the number of credits (sets the balance, used mainly to set the starting balance)
    ]]
    public class BankRoll {
    private int Balance;
    public BankRoll(int b)
    {
    Balance=b;
    }
    public int getBankRoll()
    {
    return Balance;
    }
    }
    [[Deck Class
    Information (variables):
    - An array of cards
    - The current card (this simulates the top card)
    Actions (methods):
    - Deal
    - Shuffle]]
    public class Deck {
    private int[] myDeck;
    public static final int NUMCARDS = 52;
    public Deck()
    {
    myDeck = new int[NUMCARDS];
    for(int i = 0; i<NUMCARDS; i++)
    myDeck[i] = 1;
    }
    private void current(int[] a, int i, int j)
    {
    int temp = a[i];
    a[i] = a[j];
    a[j]=temp;
    }
    public void shuffle()
    {
    int num;
    for(int i = NUMCARDS - 1; i>0; i--)
    {
    num = (int)(Math.random()*(1+i));
    current(myDeck, i, num);
    }
    }
    }
    here's what he said how to do the hand class:
    [[Hand Class
    Information (variables):
    - An array of cards
    - A Deck
    Actions (methods):
    - New Hand - 5 cards
    - Discard & Replace
    - Score - return the highest hand
    ]]
    [[here's what he said on how to do the player]]
    Hand Class
    Information (variables):
    - None specific to the player class, a Scanner is needed
    Actions (methods):
    ***I've included the the return type and parameters for each method needed to work with the Game class I provided
    - void welcome() - displays a welcome message
    - int setBankRoll() - asks for the number of credits to deposit, returns that value
    - int menu() - displays a menu with 3 choices - 1: make a bet and play, 2: add more credits, 3: quit and cash out
    - int bet() - asks user to place a bet, returns that value
    - void showScore(int payout) - displays the outcome of the hand (Royal Flush,
    - void showBalance(int balance) - displays the balance of the credits
    - void showHand(Card[] cards) - displays the hand
    - int[] discard(Card[] cards) - asks to discard each card, returns and array with responses (1 for yes, 2 for no)
    - void showWinnings(int winnings) - displays credits won on hand
    - void endGame(int balance) - displays an ending message, including final balance ]]

    here's what I have done:
    public class Player {
    public void welcome()
    {
    System.out.println("Welcome, Let's play Poker");
    }
    private int setBankRoll()
    {
    return 0;
    }
    private int menu()
    {
    return 0;
    }
    private int bet()
    {
    return 0;
    }
    private void showScore(int payout)
    {

    }
    private void showBalance(int balance)
    {

    }
    public void showHand(Card[] cards)
    {

    }
    public int[] discard(Card[] cards)
    {
    return null;
    }
    public void showWinnings(int winnings)
    {

    }
    public void endGame(int balance)
    {

    }


    }

    I do have the game class
    here is the Game class:

    public class Game {

    private Hand hand;
    private BankRoll bank;
    private Bet bet;
    private Player player;

    public Game()
    {
    hand = new Hand();
    bank = new BankRoll();
    bet = new Bet();
    player = new Player();
    }

    public void startGame()
    {
    int choice;
    int winnings;
    int payout;
    int discards[] = {0, 0, 0, 0, 0};

    player.welcome(); //Displays a welcome message
    bank.changeBankRoll(player.setBankRoll()); //Asks user to deposit credits
    choice = player.menu(); //Asks user to choose one of 3 actions - play, add credits, quit
    while(choice != 3) //repeats until user quits
    {
    if (choice == 1) //user chooses to play
    {
    bet.setBet(player.bet()); //Asks user to place a bet
    bank.changeBankRoll(-bet.getBet()); //Deducts the bet from the bankroll
    hand.newHand(); //Deals a new hand
    player.showHand(hand.getHand()); //Displays the hand to the user
    discards = player.discard(hand.getHand()); //Gets discards from user as an array - discards[#] = 1 for a discard, 2 to not discard
    for(int c = 0; c < discards.length; c++) //Loops through discard array
    if(discards[c] == 1)
    hand.discard(c); //Discards specific card
    player.showHand(hand.getHand()); //Displays hand after discards
    payout = hand.score(); //Calculates payout odds based on hand score - payout = 250 for royal flush, etc.
    player.showScore(payout); //Displays the result of the hand
    winnings = payout * bet.getBet(); //Calculates amount user wins
    if(payout != 0) //Tests if user won
    bank.changeBankRoll(winnings + bet.getBet()); //Adds winnings to the bankroll
    player.showWinnings(winnings); //Displays winnings to user
    player.showBalance(bank.getBankRoll()); //Displays bankroll balance to user

    }
    else
    {
    bank.changeBankRoll(player.setBankRoll()); //Asks user how many credits to add to bankroll
    }
    choice = player.menu(); //Displays menu of choices again
    }
    player.endGame(bank.getBankRoll()); //Displays amount of credits user has won when they quit
    }
    }
    }
    Please please please help on how to do them, and please correct the wrong ones. I am having a trouble in understanding java.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: hi I'm doing a poker game project, but I find it hard to do. Can someone please help me?

    Can you explain what you are having problems with in more detail. If you are getting errors, please copy the full text and past it here.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java Project / Library to evaluate poker hands
    By Farmer in forum Java IDEs
    Replies: 1
    Last Post: February 14th, 2012, 10:25 AM
  2. 2 Player Poker Game Troubles
    By Kaltonse in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 21st, 2010, 01:20 PM
  3. [SOLVED] Very complex project. It's hard to explain.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 55
    Last Post: November 4th, 2010, 11:30 AM
  4. help building up GUI for poker game
    By Pencil in forum AWT / Java Swing
    Replies: 5
    Last Post: October 26th, 2010, 02:53 PM
  5. Replies: 5
    Last Post: June 10th, 2010, 10:19 AM

Tags for this Thread