JAVA
Hello I have built two enum classes . Pics attached.


How can I create a list of cards from these classes .. shuffle them.. and draw 7 cards at a time
ArrayList<Card> Cards;
For this, we need to create the Card class as below:
public class Card {
CardType cardType;
// card type
Color
color;
// card color
// constructor
public Card(CardType cardType, Color color)
{
this.cardType =
cardType;
this.color =
color;
}
}
This class has card type and color.
Now, to declare the list of cards, we can do like below code in your main method:
public static void main(String[] args) {
// declare the list of
Card objects
ArrayList<Card>
Cards = new ArrayList<>();
// fill the
ArrayList as per the requirement
Cards.add(new
Card(CardType.THREE, Color.YELLOW));
Cards.add(new
Card(CardType.DRAW2, Color.BLUE));
Cards.add(new
Card(CardType.FIVE, Color.RED));
Cards.add(new
Card(CardType.FIVE, Color.GREEN));
Cards.add(new
Card(CardType.NINE, Color.GREEN));
Cards.add(new
Card(CardType.ONE, Color.YELLOW));
Cards.add(new
Card(CardType.WILD, Color.GREEN));
Cards.add(new
Card(CardType.ZERO, Color.RED));
Cards.add(new
Card(CardType.REVERSE, Color.BLUE));
Cards.add(new
Card(CardType.DRAW4, Color.RED));
// shuffle
the list
Collections.shuffle(Cards);
// create a
list for hand of 7 cards
ArrayList<Card>
hand = new ArrayList<>();
// draw 7
cards in hand, after this loop hand will have the
// 7 cards drawn from
shuffled list
for (int i = 0; i <
7; i++) {
hand.add(Cards.get(i));
}
}
This completes the requirement. Let me know if you have any questions.
Thanks!
JAVA Hello I have built two enum classes . Pics attached. How can I create a...
hello there, i have to implement this on java processing. can someone please help me regarding that? thanks War is the name of a popular children’s card game. There are many variants. After playing War with a friend for over an hour, they argue that this game must never end . However! You are convinced that it will end. As a budding computer scientist, you decide to build a simulator to find out for sure! You will implement the logic...