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

  • Home
  • SEARCH
  • 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 8853383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:38:22+00:00 2026-06-14T13:38:22+00:00

I need help in a black jack game. I have a card deck in

  • 0

I need help in a black jack game. I have a card deck in an array and every time i take a card out and deal it the array is reassgned to one less than the size. So i have this loop that deals two cards to each nth player

        deck=createCardArray();
        shuffle(deck); 
        int[] players = createPlayers(n);
        int[] points = createPoints(n);

        for(int i = 1 ; i<= players.length; i++){
            Card a = dealCard(deck);
            updatePoints(players, points, i, a);
            Card b = dealCard(deck);
            updatePoints(players, points, i, b);
            printStats(players, points, a, b);
        }

What i want to do is to print out the cards and final points after dealing two cards to each player. So I have this method printstats that looks like this:

public static void printStats(int[] nplayers, int[] points, Card a, Card b){
    for (int i=0; i<nplayers.length;i++){
        System.out.println("Player " + nplayers[i] + ": Points " + points[i]);
        System.out.println("Card 1: " + a.showCardSuit() + " " + a.showCardValue());
        System.out.println("Card 2: " + b.showCardSuit() + " " + b.showCardValue());
        System.out.println();
    }
}

What it does it that it iterates every time and outputs the cards points and players each time. But when i run this it only gives the two cards of the last player. I understand why this happens. But i want a suggestion as how to fix this problem.

Should I create a new 2d array length player and size 2Xn or is there another way I should do this?

  • 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-14T13:38:23+00:00Added an answer on June 14, 2026 at 1:38 pm

    You could improve the design by creating a Player class which contains the methods you are calling. A simple implementation would look like this.

       public class Player{
            Card a;
            Card b;
    
            public Card getA() {
                return a;
            }
            public void setA(Card a) {
                this.a = a;
            }
            public Card getB() {
                return b;
            }
            public void setB(Card b) {
                this.b = b;
            }
    
            public int points(){
                //calculation for returning point value
                int points = 0;
                return points;
            }
    
        }
    

    now instead of having 2 arrays you simply have a single array containing each player. As you loop through this array you give the player their cards by using the setA() and setB() methods. Once every player has cards, you loop through the array again and use getA() and getB() to print the cards out. Using points() gives you an easy way to calculate the points for every players hand without dragging around the extra array.

    You can make this even more useful if instead of having explicit A,B properties to hold the cards, you used a List or ArrayList. This would let you use the same system for oter card games which might not only use 2 cards.

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

Sidebar

Related Questions

I'm creating a simple black jack game using the Easy 68K simulator and need
I need syntax help with the following code logic: I have a code block
Need help with a query that I wrote: I have three tables Company id
need help to create regular expression matching string www.*.abc.*/somestring Here * is wild card
need help/guide for sql select query, I have 2 table stock and stock_history, in
need help regarding USSD Gateway. I have to develop an app, which will directly
need help in error in database pivot. i have table tamed table_score like below:
Quick question, I need help and have no idea what to do, because I
I need your help :) I have a EditText and below a ExpandableListView. I
I need help with this mistake. I have created a Runnable jar with two

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.