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...
How can I split this program into two classes? import java.io.*; public class Quiz { static LineNumberReader cin = new LineNumberReader(new InputStreamReader(System.in)); public static void main(String[] args) { int score = 0; final int NumberofQuestions = 5; int num; System.out.println("\nWelcome to CSC 111 Java Quiz\n"); String[][] QandA = { {"All information is stored in the computer using binary numbers: ","true"}, {"The word \"Public\" is a reserved word: ","false"}, {"Variable names may begin with a number: ","false"}, {"Will the...
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...
I have to create two classes one class that accepts an object, stores the object in an array. I have another that has a constructor that creates an object. Here is my first class named "ShoppingList": import java.util.*; public class ShoppingList { private ShoppingItem [] list; private int amtItems = 0; public ShoppingList() { list=new ShoppingItem[8]; } public void add(ShoppingItem item) { if(amtItems<8) { list[amtItems] = ShoppingItem(item);...
Hi! I need help with a C++ program In this assignment, you will create some routines that will later be used in a "Black Jack" program. Your output on this first part will look something like: card's name is QC with a black jack value of 10 Unshuffled Deck AC/1 2C/2 3C/3 4C/4 5C/5 6C/6 7C/7 8C/8 9C/9 TC/10 JC/10 QC/10 KC/10 AD/1 2D/2 3D/3 4D/4 5D/5 6D/6 7D/7 8D/8 9D/9 TD/10 JD/10 QD/10 KD/10 AH/1 2H/2 3H/3 4H/4 5H/5...
Using the classes from Lab 1, app and student, create a solution for implementing some kind of random behavior for your student. Suppose the student can be reading, surfing the web, or interacting with other students. You will need to check now and then to see what the student is doing. You will be asking the instance of the student class and what it is doing at certain time intervals. You Will Need To: Create a method in the class...