Question: Hi , im doing java coding and i have the following codes I need to complete so that they successfully run against the tests given
Hi im doing java coding and i have the following codes I need to complete so that they successfully run against the tests given below:
public class DeckClient
public static void mainString args
Deck deck new Deck;
deck.shuffle;
public class DeckTest
public static Deck deck;
public static ArrayList cards;
@BeforeAll
public static void init
deck new Deck;
cards new ArrayList;
ArrayList suits new ArrayList;
String suitNames CSVReader.readdatasuitscsv;
forString suitName : suitNames
String suitDetails suitName.split;
suits.addnew SuitsuitDetails suitDetailscharAt suitDetails Integer.parseIntsuitDetails;
ArrayList ranks new ArrayList;
String rankNames CSVReader.readdatarankscsv;
forString rankName : rankNames
String rankDetails rankName.split;
ranks.addnew RankrankDetails rankDetailscharAt Integer.parseIntrankDetails;
forSuit suit : suits
forRank rank : ranks
cards.addnew Cardrank suit;
@Test
@Gradeddescription "Deck constructor", marks
@Order
public void testDeckConstructor
Deck object already constructed in init Check them out
assertEqualscardssize deck.cards.size;
forint i ; i cards.size; i
assertTruecardsgetiequalsdeckcards.geti;
currentMethodName new ObjectgetClassgetEnclosingMethodgetName;
@Test
@Gradeddescription "Deck shuffle", marks
@Order
public void testDeckShuffle
ArrayList freq new ArrayList;
forint i; i deck.cards.size; i
freq.add;
ArrayList arrangements new ArrayList;
int count ;
forint i; i ; i
deck.shuffle;
arrangements.adddecktoString;
assertTrueallUniquearrangements;
currentMethodName new ObjectgetClassgetEnclosingMethodgetName;
private boolean allUniqueArrayList arrangements
forint i; i arrangements.size; i
forint ji; j arrangements.size; j
ifarrangementsgetiequalsarrangementsgetj
return false;
return true;
@Test
@Gradeddescription "Deck drawCard", marks
@Order
public void testDeckDrawCard
deck new Deck;
assertEquals deck.cards.size;
forint i; i ; i
int sizeBefore deck.cards.size;
Card card deck.drawCard;
int sizeAfter deck.cards.size;
assertNotNullcard;
assertEqualssizeBefore sizeAfter;
assertNulldeckdrawCard; no more cards left
assertEquals deck.cards.size;
currentMethodName new ObjectgetClassgetEnclosingMethodgetName;
here are the codes to complete
package toBeCompleted.stage;
import java.util.ArrayList;
import toBeCompleted.stage;
public class Deck
public ArrayList cards;
Constructor for Deck
Initializes the deck with cards.
ranks and suits.
The four suits are:
Hearts color "red", symbol value
Diamonds color "red", symbol value
Clubs color "black", symbol value
Spades color "black", symbol value
The ranks are:
name symbol value
name symbol value
name symbol value
name symbol value
name symbol value
name symbol value
name symbol value
name symbol value
name symbol X value
name "Jack", symbol J value
name "Queen", symbol Q value
name "King", symbol K value
name "Ace", symbol A value
Besides ArrayList and the classes from stage
the constructor should not import any other libraryclass
even from within the project.
public Deck
TODO
Shuffles the deck. If you are not passing the tests,
it is most likely because you are either not swapping cards correctly,
or not making sufficient swaps.
public void shuffle
TODO
Draws a card from the deck.
@return Card drawn from the deck, null if deck is empty
public Card drawCard
return null; TODO
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
