I am trying to write a solitiare game on java. I'm trying to add the card objects to my arraylist but the MakeDeck function is not working properly.
public class PileOfCards {
public ArrayList<Card> pile = new ArrayList<Card>();
Card tempo;
public PileOfCards() {
pile = new ArrayList<Card>();
}
public void MakeDeck() {
for (int i=0;i<13;i++){
tempo = new Card(i+1, "FaceDown", "Clubs");
pile.add(tempo);
}
for (int j=0;j<13;j++){
tempo = new Card(j+1, "FaceDown", "Diamonds");
pile.add(tempo);
}
for (int k=0;k<13;k++){
tempo = new Card(k+1, "FaceDown", "Hearts");
pile.add(tempo);
}
for (int l=0;l<13;l++){
tempo = new Card(l+1, "FaceDown", "Spades");
pile.add(tempo);
}
}
When I'm trying to print the values it prints "0, null, null" , 52 times. What is the problem? It looks like I can't reach to the ArrayList, but I don't know why.
Edited:
Card constructor:
public Card(int valueTemp, String suitTemp, String statusTemp) {
valueTemp = value;
suitTemp = suit;
statusTemp = status;
}
Print function:
public void printPile(){
for(int i=0;i<pile.size();i++){
System.out.print(pile.get(i).status);
System.out.print(" ");
System.out.print(pile.get(i).suit);
System.out.print(" ");
System.out.print(pile.get(i).value);
System.out.printf("\n");
}
Card1to the loop variable then why not dofor (int i=1; i <= 13; i++) ...