I can't figure out how to make and handle multiple stacks and use them so I could create four linked list stacks representing each suit of cards, one stack each for diamonds, hearts, spades, and clubs. I use objects as my cards. I don't know how to make more than one stack.
Can anyone help me out? If I'm not being clear, I'll be happy to clarify the problem I have.
here is the class I used to make the Objects for cards,
and here is the class I'm building to make the four stacks for each suit.
Can anyone help me out? If I'm not being clear, I'll be happy to clarify the problem I have.
here is the class I used to make the Objects for cards,
Code:
public class Cards {
String sRank = "";
String sSuit = "";
int rank = 1;
int suit = 1;
Object suitAndRank;
public String switchSuit(int suit) {
if(suit == 0)
sSuit = "D";
else if(suit == 1)
sSuit = "H";
else if(suit == 2)
sSuit = "S";
else if(suit == 3)
sSuit = "C";
else
sSuit = null;
return sSuit;
}
public String switchRank(int rank) {
if (rank == 0)
sRank = "A";
else if (rank == 1)
sRank = "2";
else if (rank == 2)
sRank = "3";
else if (rank == 3)
sRank = "4";
else if (rank == 4)
sRank = "5";
else if (rank == 5)
sRank = "6";
else if (rank == 6)
sRank = "7";
else if (rank == 7)
sRank = "8";
else if (rank == 8)
sRank = "9";
else if (rank == 9)
sRank = "10";
else if (rank == 10)
sRank = "J";
else if (rank == 11)
sRank = "Q";
else if (rank == 12)
sRank = "K";
else
sRank = null;
return sRank;
}
public Object switchSuitAndRank(int rank, int suit) {
sSuit = switchSuit(suit);
sRank = switchRank(rank);
suitAndRank = switchRank(rank) + switchSuit(suit);
return suitAndRank;
}
}
Code:
public class PushFourSuits {
Object x;
Object toBeDisplayed;
int rank = 0;
LinkedStack diam = new LinkedStack();
LinkedStack heart = new LinkedStack();
LinkedStack spad = new LinkedStack();
LinkedStack club = new LinkedStack();
Cards cards = new Cards();
public void diamondStack(){
int suit = 0;
for(rank = 0; rank <= 12; rank++){
x = cards.switchSuitAndRank(suit, rank);
diam.push(x);
}
}
public void heartStack(){
int suit = 1;
for(rank = 0; rank <= 12; rank++){
x = cards.switchSuitAndRank(suit, rank);
heart.push(x);
}
}
public void spadeStack(){
int suit = 2;
for(rank = 0; rank <= 12; rank++){
x = cards.switchSuitAndRank(suit, rank);
spad.push(x);
}
}
public void clubStack(){
int suit = 3;
for(rank = 0; rank <= 12; rank++){
x = cards.switchSuitAndRank(suit, rank);
club.push(x);
}
}
}
Comment