我想打印我的 ArrayList FullDeckArray 以查看我的 Deck 是否包含所有 52 张卡片和值。
这是我下面的卡片和甲板课程
package blackjack;
/**
*
* @author mvisser
*/
public class Card
{
private int rank;
private int suit;
public String tostring(Card card1)
{
String result = "";
if (rank == 1) {
result = "Ace";
}
if (rank == 2) {
result = "Two";
}
if (rank == 3) {
result = "Three";
}
if (rank == 4) {
result = "Four";
}
if (rank == 5) {
result = "Five";
}
if (rank == 6) {
result = "Six";
}
if (rank == 7) {
result = "Seven";
}
if (rank == 8) {
result = "Eight";
}
if (rank == 9) {
result = "Nine";
}
if (rank == 10) {
result = "Ten";
}
if (rank == 11) {
result = "Jack";
}
if (rank == 12) {
result = "Queen";
}
if (rank == 13) {
result = "King";
}
if (suit == 1) {
result = result + " of Clubs ";
}
if (suit == 2) {
result = result + " of Diamonds ";
}
if (suit == 3) {
result = result + " of Hearts ";
}
if (suit == 4) {
result = result + " of Spades ";
}
return result;
}
public Card(int rank, int suit)
{
this.rank = rank;
this.suit = suit;
}
}
正如您在我的 Deck Class 中看到的那样,我有一个 ArrayList FullDeckArray,我要做的就是将
它打印出来,看看带来了什么价值
public class Deck
{
// private Card[][] fullDeck = new Card[0][0];
private Random shuffle = new Random();
public ArrayList<Card> FullDeckArray = new ArrayList<Card>();
// private int numberOfCards = 52;
public Deck()
{
for (int rank = 1; rank <= 13; rank++) {
for (int suit = 1; suit <= 4; suit++)
{
FullDeckArray.add(new Card(rank, suit));
}
}
}
public void shuffle() {
Collections.shuffle(FullDeckArray);
}
public Card DrawCard() {
int cardPosition = shuffle.nextInt(FullDeckArray.size()+1);
return FullDeckArray.remove(cardPosition);
}
public int TotalCards() {
return FullDeckArray.size();
}
public void test() {
System.out.println( ArrayList<Card>( FullDeckArray ) );
}
}