So this is my main class: It creates a CradStack Object and uses the mixCards method, which you will see in the next class block.
package BlackJack;
public class BlackJack {
public static void main(String[] args) {
CardStack cs = new CardStack();
cs.mixCards();
//cs.pop();
}
public BlackJack() {
}
public void calculateHand() {
}
public void compareHands() {
}
}
This is the CardStack class: It extends Stack and till now has only the method mix Cards which fills the Stack with 312 Cards (6decks à 13 types à 4 suites and than mixes it with the Collections.shuffle method. This should work.
package BlackJack;
import java.util.Collections;
import java.util.Stack;
public class CardStack extends Stack {
public CardStack() {
}
public void mixCards() {
Stack st = new Stack();
for (int i = 0; i < 6; i++) {
for (int k = 0; k < 13; k++) {
for (int l = 0; l < 4; l++) {
Card cd = new Card();
cd.setValue(k);
cd.setColor(l);
st.push(cd);
}
}
}
Collections.shuffle(st);
}
}
This is the Card Class: I will implement the suite/color as an enum later on
package BlackJack;
public class Card {
private int value;
private String color;
//enum Suit { HEARTS, DIAMONDS, CLUBS, SPADES };
public void setValue(int value) {
this.value = value;
}
public void setColor(int l) {
if (l == 0) {
this.color="Hearts";
}
if (l == 1) {
this.color="Clubs";
}
if (l == 2) {
this.color="Diamonds";
}
if (l == 3) {
this.color="Spades";
}
}
public int getValue() {
return value;
}
public String getColor() {
return color;
}
}
Can someone explain why i do get an EmptyStackException when i use cs.pop ?