Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using DrJava create a program that does the following: 1. Write a class named Ca

ID: 3694544 • Letter: U

Question

Using DrJava create a program that does the following:

1. Write a class named Card. It can be used to represent a (single) card from a deck of cards. The class should be able to store a card's suit and face value. A card's suit is one of the following: Hearts, Diamonds, Spades, or Clubs. A card's face value is one of: Ace, Jack, Queen, King, or a value in the range of two through ten.

2. Write a class named Deck. This class's constructor should create a list of 52 Card objects, each representing a valid card in a deck of cards. You must implement the list of card objects using one of the classes or interfaces found in chapter 19 or 20. You cannot use facilities discussed further in the book.

3. Your Deck class must have a method called shuffle(). This method randomly shuffles the Card objects in the list.

4. You Deck class must have a method called deal(). It deals a card by removing the Card object at the beginning of the list and returns a reference to that object (i.e. the Card object).

5. Write a CardPlayer class. This class needs to keep a list of Card objects that have been dealt to it. (See 4). This can be used to represent a hand of cards.

6. Write a method in the CardPlayer class called getCard().   getCard gets passed to it a reference to a Card object and adds it to the list (maintained by CardPlayer).

7. Write a method in the CardPlayer class called showCards().   showCards displays (all of the) Card objects in the list.

8. Write a driver/test program which

   a) Creates a Deck object

   b) shuffles the cars it contains

   c) deals 5 cards from the Deck to a CardPlayer object.

   d) displays the cards in the CardPlayer object using the showCards method.

Explanation / Answer

public class CardDeck{


String[] suits = {"Spades", "Hearts", "Diamonds", "Clubs"};
String[] face = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};

public String toString()
{
String s = "";
int k;

k = 0;
for ( int i = 0; i < 4; i++ )
{
for ( int j = 1; j <= 13; j++ )
s += ( deckOfCards[k++] + " " );

s += " "; // Add NEWLINE after 13 cards
}
return ( s );
}
// Shuffle the cards
public void shuffle() {
Collections.shuffle(this.cards);
}
public deal()
{
  
    if ( currentCard < NCARDS )
    {
    return ( deckOfCards[ currentCard++ ] );
    }
    else
    {
    System.out.println("Out of cards error");
    return ( null ); // Error;
    }

public void showcards(){

for(int i=0;i<suits.length;i++){

for(int j=0;j<values.length;j++){
System.out.print(cards[cardPointer++]+" ");
}

System.out.println(" ");

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote