Мне нужно распечатать колоду из 52 уникальных карт, используя ArrayList и вложенный цикл for. Я сделал это только с помощью массивов, но я не могу вместо этого обернуть голову, используя ArrayList. Спасибо за любую помощь, спасибо.
Переменные экземпляра:
public final String[] SUITS = {"Hearts", "Diamonds", "Spades", "Clubs"};
public final String[] DESCRIPTIONS = {"Ace", "Two", "Three", "Four",
"Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen",
"King"};
private ArrayList<Card> deck;
Способ добавления моей колоды в ArrayList:
public void loadDeck1()
{
deck = new ArrayList<Card>();
for(int i = 0; i < DESCRIPTIONS.length; i++)
{
for(int j =0; j < SUITS.length; j++)
{
**deck.add(new Card(DESCRIPTIONS[i], SUITS[j]));
// BlueJ Error: actual and formal argument lists differ in length**
}
}
}
Способ печати на колоде:
public void printDeck()
{
for(Card c : deck)
{
System.out.println(c.getSuit() + " of " + c.getDescription());
}
}
edit: Извините, вот мой класс карт!
public class Card
{
private String suit;
private String description;
/**
* Constructor for objects of class Card
*/
public Card()
{
suit = null;
description = null;
}
/**
* Accessors
*/
/**
* @return the suit of the card
*/
public String getSuit()
{
return this.suit;
}
/**
* @return the description of the card
*/
public String getDescription()
{
return this.description;
}
/**
* Mutators
*/
/**
* @param the suit of the card
*/
public void setSuit(String suit)
{
this.suit = suit;
}
/**
* @param the description of the card
*/
public void setDescription(String description)
{
this.description = description;
}
}