Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PLEASE HELP IN JAVA NOT C# ! ! ! Begin with the following code, and the class you defined in # 1 ( you can
PLEASE HELP IN JAVA NOT C# Begin with the following code, and the class you defined in #you can assume it works even if you
couldnt code #:
Add code to do the following things:
Create an ArrayList java or List called Deck of PlayingCard the Class you defined in the
previous question
a You will put an object of type PlayingCard into each cell of the ArrayListList
b The first PlayingCard should be an A of Clubs ie its value should be A its suite
should be Clubs. Next add a of Clubs of Clubs of ClubsQ of ClubsK
of Clubs
c Repeat step b above for Diamonds, Hearts and Spades.
d Thus youll add all values A J Q K of each of the suites,
so you should end up adding PlayingCard objects to the ArrayList.
e Hint: You should use a nested loop to do this step
Next, you will create a hand of unique cards in a new ArrayListList
a Youll do this by picking a random number between and using:
Java: int posmyrand.nextInt;
b If youve not picked that number before, youll add the card that is in the Deck
ArrayListList at that position you just randomly picked to the Hand ArrayListList
c Youll have to keep track of which numbers youve picked so you dont accidentally add
the same card twice.
Finally, print out the cards of the hand ArrayListList You must use the toString Java override you put in the class in the last question.
Java
import java.util.ArrayList;
import java.util.Random;
class Main
public static void mainString args
Random myrand new Random;
String suites
Clubs"Diamonds","Hearts","Spades";
String values
AJ
QK;
Insert code here
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started