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 main(String[] 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.read("data/suits.csv");
for(String suitName : suitNames){
String[] suitDetails = suitName.split(",");
suits.add(new Suit(suitDetails[0], suitDetails[1].charAt(0), suitDetails[2], Integer.parseInt(suitDetails[3])));
}
ArrayList ranks = new ArrayList();
String[] rankNames = CSVReader.read("data/ranks.csv");
for(String rankName : rankNames){
String[] rankDetails = rankName.split(",");
ranks.add(new Rank(rankDetails[0], rankDetails[1].charAt(0), Integer.parseInt(rankDetails[2])));
}
for(Suit suit : suits){
for(Rank rank : ranks){
cards.add(new Card(rank, suit));
}
}
}
@Test
@Graded(description = "Deck constructor", marks =10)
@Order(1)
public void testDeckConstructor(){
//Deck object already constructed in init(). Check them out
assertEquals(cards.size(), deck.cards.size());
for(int i =0; i < cards.size(); i++){
assertTrue(cards.get(i).equals(deck.cards.get(i)));
}
currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName();
}
@Test
@Graded(description = "Deck shuffle", marks =10)
@Order(2)
public void testDeckShuffle(){
ArrayList freq = new ArrayList();
for(int i=0; i < deck.cards.size(); i++){
freq.add(0);
}
ArrayList arrangements = new ArrayList();
int count =0;
for(int i=0; i <20000; i++){
deck.shuffle();
arrangements.add(deck.toString());
}
assertTrue(allUnique(arrangements));
currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName();
}
private boolean allUnique(ArrayList arrangements){
for(int i=0; i < arrangements.size(); i++){
for(int j=i+1; j < arrangements.size(); j++){
if(arrangements.get(i).equals(arrangements.get(j))){
return false;
}
}
}
return true;
}
@Test
@Graded(description = "Deck drawCard", marks =10)
@Order(3)
public void testDeckDrawCard(){
deck = new Deck();
assertEquals(52, deck.cards.size());
for(int i=0; i <52; i++){
int sizeBefore = deck.cards.size();
Card card = deck.drawCard();
int sizeAfter = deck.cards.size();
assertNotNull(card);
assertEquals(sizeBefore -1, sizeAfter);
}
assertNull(deck.drawCard()); //no more cards left
assertEquals(0, deck.cards.size());
currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName();
}
*here are the codes to complete*
package toBeCompleted.stage2;
import java.util.ArrayList;
import toBeCompleted.stage1.*;
public class Deck {
public ArrayList cards;
/**
* Constructor for Deck
* Initializes the deck with 52 cards.
*13 ranks and 4 suits.
*
* The four suits are:
* Hearts (color = "red", symbol ='', value =1),
* Diamonds (color = "red", symbol ='', value =2),
* Clubs (color = "black", symbol ='', value =3),
* Spades (color = "black", symbol ='', value =4)
*
* The 13 ranks are:
*
* name ="2", symbol ='2', value =2
* name ="3", symbol ='3', value =3
* name ="4", symbol ='4', value =4
* name ="5", symbol ='5', value =5
* name ="6", symbol ='6', value =6
* name ="7", symbol ='7', value =7
* name ="8", symbol ='8', value =8
* name ="9", symbol ='9', value =9
* name ="10", symbol ='X', value =10
* name = "Jack", symbol ='J', value =11
* name = "Queen", symbol ='Q', value =12
* name = "King", symbol ='K', value =13
* name = "Ace", symbol ='A', value =14
*
* Besides ArrayList and the classes from stage 1,
* the constructor should not import any other library/class,
* 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!