Answered step by step
Verified Expert Solution
Link Copied!

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 #1(you can assume it works even if you
couldnt code #1):
Add code to do the following things:
1) 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 ArrayList/List.
b) The first PlayingCard should be an A of Clubs, ie, its value should be A, its suite
should be Clubs. Next add a 2 of Clubs,3 of Clubs,4 of Clubs...Q of Clubs...K
of Clubs.
c) Repeat step b above for Diamonds, Hearts and Spades.
d) Thus youll add all 13 values (A,2,3,4,5,6,7,8,9,10, J, Q, K) of each of the 4 suites,
so you should end up adding 52 PlayingCard objects to the ArrayList.
e) Hint: You should use a nested loop to do this step
2) Next, you will create a hand of 5 unique cards in a new ArrayList/List.
a) Youll do this by picking a random number between 0 and 51 using:
Java: int pos=myrand.nextInt(51);
b) If youve not picked that number before, youll add the card that is in the Deck
ArrayList/List at that position you just randomly picked to the Hand ArrayList/List
c) Youll have to keep track of which numbers youve picked so you dont accidentally add
the same card twice.
3) Finally, print out the 5 cards of the hand ArrayList/List. 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 main(String[] args){
Random myrand = new Random();
String[] suites =
{"Clubs","Diamonds","Hearts","Spades"};
String[] values =
{"A","2","3","4","5","6","7","8","9","10","J",
"Q","K"};
//Insert code here
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications Dasfaa 2023 International Workshops Bdms 2023 Bdqm 2023 Gdma 2023 Bundlers 2023 Tianjin China April 17 20 2023 Proceedings Lncs 13922

Authors: Amr El Abbadi ,Gillian Dobbie ,Zhiyong Feng ,Lu Chen ,Xiaohui Tao ,Yingxia Shao ,Hongzhi Yin

1st Edition

3031354141, 978-3031354144

More Books

Students also viewed these Databases questions