I'm using a Linked list stack with objects. I figured out the reason for my earlier problem (where I couldn't access "rank" and "suit" from one of the objects in my stack), and it was because my object didn't have the attributes "rank" and "suit". Turns out my earlier cards were practically just strings. Can anyone help me create a whole deck of cards represented by 52 objects in a linked list stack with the attributes "suit" and "rank"?
This is where I try to create the deck.
This is the card class. I tried making a constructor, but I'm really not very familiar with using them (this is only the second time I've tried to make one), so sorry for the messiness and the overall chaos of my codes.
Thank you to everyone who has been answering question after question I post, and for their patience with me. They've all been so completely helpful. :)
This is where I try to create the deck.
Code:
Cards[] cards = new Cards[52]; Cards acards = new Cards(); public void deck(){ for(int i=0; i<=51; i++) { for(suit = 0; suit <= 3; suit++) { for(rank = 0; rank <= 12; rank++){ cards[i] = new Cards(); String sRank = ""; rank = acards.getRank(); suit = acards.getSuit(); System.out.println(cards[i]); } } } }
Code:
public Cards(String sRank, String sSuit, boolean avisibility) { toStringRank() = sRank; toStringSuit() = sSuit; visibility = avisibility; } public int getRank() { return rank; } public int getSuit() { return suit; } public String toStringRank() { if (a == 0) sRank = "A"; else if (a == 1) sRank = "2"; else if (a == 2) sRank = "3"; else if (a == 3) sRank = "4"; else if (a == 4) sRank = "5"; else if (a == 5) sRank = "6"; else if (a == 6) sRank = "7"; else if (a == 7) sRank = "8"; else if (a == 8) sRank = "9"; else if (a == 9) sRank = "10"; else if (a == 10) sRank = "J"; else if (a == 11) sRank = "Q"; else if (a == 12) sRank = "K"; else sRank = null; return sRank; } public String toStringSuit() { if (a == 0) sSuit = "D"; else if (a == 1) sSuit = "H"; else if (a == 2) sSuit = "S"; else if (a == 3) sSuit = "C"; else sSuit = null; return sSuit; }
Thank you to everyone who has been answering question after question I post, and for their patience with me. They've all been so completely helpful. :)
Comment