I see a lot of questions like this, but they are answered by code that I have not yet studied. I should be able to complete this task without an arraylist, so this creates a problem for me. I need to play the war: create a card class, create a deck, and then randomly create the first card, “remove” the card from the deck and create the second card to see which card won, continue this comparison until the deck is exhausted. Here is what I still have:
public class Card
{
private int cardValue;
private String cardSuit;
private String stringValue;
static final String[] SUIT = {"Clubs", "Diamonds", "Hearts", "Spades"};
static final String[] VALUE = {"Ace","Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
public Card (int cardS, int cardV)
{
cardSuit = SUIT[cardS];
stringValue = VALUE[cardV];
}
public String getCardSuit()
{
return cardSuit;
}
public String getValue()
{
return stringValue;
}
public String toString()
{
return String.format("%s of %s", stringValue, cardSuit);
}
}
public class Deck
{
private final int HIGH_SUIT=3;
private final int HIGH_VALUE=12;
int i = 0;
int cardCount;
Card[] fullDeck = new Card[52];
public Deck()
{
for(int s = 0; s <= HIGH_SUIT; s++)
{
for (int v = 0; v <= HIGH_VALUE; v++)
{
fullDeck[i] = new Card(s, v);
cardCount = (i + 1);
i++;
}
}
}
}
public class War3
{
public static void main(String[] args)
{
int i=0;
Deck[] fullDeck = new Deck[52];
int r = ((int) (Math.random() * 100) % 51);
Card[] playerCard = new Card[r];
System.out.println("The card is: " + playerCard.toString());
}
, 3, , . : : [LCard; @4a5ab2random # 1
? , , , . .