Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8421511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:10:23+00:00 2026-06-10T03:10:23+00:00

Please, any help would be greatly appreciated and I’m sure this should be a

  • 0

Please, any help would be greatly appreciated and I’m sure this should be a simply problem.

I am a university student, very new to Java, and attempting some lab course work.

The requirement is quite a simple poker program, which simply needs to:
Generate a deck of 52 cards in a specified order (already functional)
Read in number of players, and player names (already functional)
Deal 5 cards to each (2) players and the dealer from the top of the deck (unsure if functional)
Then display the cards via the following output:

Number of players: 2
Player 1: Homer
Player 2: Marge

Homer has AH 4H 7H 10H KH
Marge has 2H 5H 8H JH AD
Dealer has 3H 6H 9H QH 2D


There are several classes – Dealer, Player, Deck, Hand, Card

Now the output I am getting is:

Number of players: 2
Player 1: Homer
Player 2: Marge

Homer has KH KH KH KH KH
Marge has AD AD AD AD AD
Dealer has 2D 2D 2D 2D 2D


The relevant code for the Dealer class:

public class Dealer {
    public static void main(String[] args)
    {   new Dealer();  }

    private Deck deck = new Deck();
    private Hand hand = new Hand();
    public ArrayList<Player> players = new ArrayList<Player>();

    ....

    private void deal()
    {
        for(int i = 0; i < 5; i ++) {
            for (Player player : players)
                player.add(next());
            add(next());  
        }
    }    //  deal five cards to each player and the dealer
         //  in the stated order

    private void add(Card card)
    {   hand.add(card);    }

    private Card next()
    {   return deck.next(); }

    private void show()
    {   
        for (Player player : players)
            System.out.println(player.getName() + " has " + player.showHand());
        System.out.println("Dealer has " + hand.toString());
    }
}

Here is the relevant code in the Player class:

public class Player{
    private String name;
    private int number;
    private Hand hand = new Hand();
    ....
    public void add(Card card)
    {   hand.add(card); }

    public String showHand()
    {
        String show = "" + hand.toString();
        return show;
    }

Here is the relevant code in the Hand class:

public class Hand {
    private Card[] cards = new Card[5];
    ....
    public void add(Card card)
    {
        for (int i = 0; i < cards.length; i++)
            cards[i] = new Card(card.valueReturn(), card.suitReturn());
    }

    public String toString()
    {
        String display = "";
        display = cards[0].toString() + cards[1].toString() + cards[2].toString() + cards[3].toString() + cards[4].toString();
        return display;
    }
}

Here is the relevant code from the Deck class:

public class Deck{
    private Card[] cards = new Card[52];
    private int i = 0, deck = 0;
    private char[] suits = {'H', 'D', 'C', 'S'};

    public Deck()
    {
        for (int suit = 0; suit < 4; suit++){
            for(int value = 1; value <= 13; value++){
                 cards[deck++] = new Card(value, suits[suit]);
            } 
        }        
    }  // create the cards in the stated order and add them to the deck

    //  This function works by side effect
    //  It uses the standard "next" pattern you will see next week
    public Card next()
    {   return cards[i++];    }
}

And finally here is the relevant code from the Card class:

public class Card{

    private int cardValue;
    private char suit;

    public Card(int cardValue, char suit)
    {   
        this.cardValue = cardValue;
        this.suit = suit;   
    }

    public String valueDisplay()
    {
        switch (cardValue)
        {
            case 1: return "A";
            case 11: return "J";
            case 12: return "Q";
            case 13: return "K";
            default: return "" + cardValue;
        }
    }

    public int valueReturn()
    {
        this.cardValue = cardValue;
        return cardValue;
    }

    public char suitReturn()
    {
        this.suit = suit;
        return suit;
    }

    public String toString()
    {
        return valueDisplay() + suit + " ";
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:10:24+00:00Added an answer on June 10, 2026 at 3:10 am

    In Hand.add():

    for (int i = 0; i < cards.length; i++)
       cards[i] = new Card(card.valueReturn(), card.suitReturn());
    }
    

    You are creating five new cards with exactly the same values.

    One would expect something like (ugly but quick fix):

    for (int i = 0; i < cards.length; i++)
       if (cards[i] == null) {
         cards[i] = card;
         return;
       } 
    }
    

    Additionally, for these situations, learning to use the debugger and watch your system status step by step is very useful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit new to using nth-child() so any help would be greatly appreciated.
Can any one please help me solve this. I am resizing some flash object/embed
Hey friends any one please help me for this issue.in this javascript code i
Can any one please help me how to go to another activity in android
Any one please help me to build a horizontal bar graph in my android
How to check visited link using jquery without using any plugin please help to
Any body please can please help me, how to center a JFrame on Mac.
Please help me understand the following code snippet :- def any(l): whether any number
Please any one give me the suggestion for this. I'm having the Xerces-J-source.zip file
Can someone please help. I have been searching and encountered/modified this code I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.