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 8843339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:11:44+00:00 2026-06-14T11:11:44+00:00

I am trying to build a blackjack game. I have created a deck, now

  • 0

I am trying to build a blackjack game. I have created a deck, now I want to display it.

I know I’m doing something wrong because I cannot access displayStack within CardStack class. Also, I have a feeling that I’m not doing inheritance correctly. How could I fix this?

Here is my code:

public class CreateCardDeck {
    int deckSize = 52;
    CardStack cardStack = new CardStack(deckSize);

    public void CreateDeck() {
        String[] suit = {"clubs", "diamonds", "hearts", "spades"};
        int[] rank = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};

        for (int i = 0; i < rank.length; i ++) {
            for (int j = 0; j < suit.length; j++) {
                cardStack.push(suit[j], rank[i]);
            }
        }
    }
}

Card class:

class Card {
    String suit;
    int rank;

    Card(String suit, int rank) {
        this.suit = suit;
        this.rank = rank;
    }

    public String getSuit() {
        return suit;
    }

    public String getRank() {
        String nameTheRank;
        if (rank == 1)
            nameTheRank = "Ace";
        else if (rank == 11)
            nameTheRank = "Jack";
        else if (rank == 12)
            nameTheRank = "Queen";
        else if (rank == 13)
            nameTheRank = "King";
        else
            nameTheRank = String.valueOf(rank);
        return nameTheRank;
    }
}

CardStack class:

class CardStack {
    public void displayDeck() {
        for (int i = 0; i < stackArray.length; i ++)
            System.out.println(stackArray[i]);
    }
}

The Main Class:

public class MainClass {
    public static void main(String[] args) throws IOException {
        CreateCardDeck c = new CreateCardDeck();
        c.CreateDeck();
        // How to display my deck?
    }
}
  • 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-14T11:11:45+00:00Added an answer on June 14, 2026 at 11:11 am

    I would redesign your types to start with. CreateCardDeck sounds like it should really be a static method called createDeck within a CardDeck or possibly just Card type. It also sounds like the knowledge of suits and number shouldn’t really be part of that method. Cards are often used as a demonstration of enums in Java – one enum for the values (ace to king) and one for the suits.

    Think about what it really means to have an instance of CreateCardDeck – does that really make sense to you? It feels more like a verb (a method) than a noun (a type).

    Now you could have a CardDeckFactory or something similar – but then I wouldn’t expect the deck to be part of the state of the object; it would just be returned by a method.

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

Sidebar

Related Questions

I have a std::vector< tr1::shared_ptr<mapObject> > that I'm trying build from data contained in
Trying to build dynamic output from json and using jq/template tmpl display rows/columns. Somehow
Im trying to build a simple, lightweight product viewer using jquery. I have a
Trying to build a ajax comment system .I have a list populated from MYSQL
I am trying build a jQuery EasyUI datagrid or treegrid out of a large
I was trying Build For Archiving application (from Titanium Mobile) with xCode 4.4, but
I'm trying build a method which returns the shortest path from one node to
I'm trying build an App Engine connected Android application and am having some problems
I'm trying build a MVC framework, but I'm confused about manage themes. Well... I
Trying to build out an exception if move.UserId does not equal currentUserId then Redirect

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.