In Assignment 4, you created a Card class that represents a standard playing card. Use this to design and implement a class called DeckOfCards that stores 52 objects of the Card class using an array. Include methods to shuffle the deck, deal a card, return the number of cards left in the deck, and a toString to show the contents of the deck. The shuffle methods should assume a full deck. Document your design with a UML Class diagram. Create a separate driver class that first outputs the populated deck to prove it is complete, shuffles the deck, and then deals each card from a shuffled deck, displaying each card as it is dealt along with the number of cards left in the deck.   Hint: The constructor for DeckOfCards should have nested for loops for the face values (1 to 13) within the suit values (1 to 4) calling the two parameter constructor. The shuffle method does not have to simulate how a deck is physically shuffled; you can achieve the same effect by repeatedly swapping pairs of cards chosen at random. Testing: Include two complete runs to demonstrate the random effect of shuffling.

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter9: Using Classes And Objects
Section: Chapter Questions
Problem 2CP
icon
Related questions
Question
  1. In Assignment 4, you created a Card class that represents a standard playing card. Use this to design and implement a class called DeckOfCards that stores 52 objects of the Card class using an array. Include methods to shuffle the deck, deal a card, return the number of cards left in the deck, and a toString to show the contents of the deck. The shuffle methods should assume a full deck. Document your design with a UML Class diagram. Create a separate driver class that first outputs the populated deck to prove it is complete, shuffles the deck, and then deals each card from a shuffled deck, displaying each card as it is dealt along with the number of cards left in the deck.

     

    Hint: The constructor for DeckOfCards should have nested for loops for the face values (1 to 13) within the suit values (1 to 4) calling the two parameter constructor. The shuffle method does not have to simulate how a deck is physically shuffled; you can achieve the same effect by repeatedly swapping pairs of cards chosen at random.

    Testing: Include two complete runs to demonstrate the random effect of shuffling.

 

This is the card 

also please with comments 

 

import java.util.Random;

public class Card {
  
private int face;
private int suit;
public static final int suit_values[]={1,2,3,4};
public static final int face_values[]={1,2,3,4,5,6,7,8,9,10,11,12,13};

//All constants are declared in a string array which is made as static and final, so that it remains same across the objects and can be maintained globally
public static final String suit_literals[]={"Diamonds","Clubs","Hearts","Spades"};
public static final String face_literals[]={"Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"};
  
Card(){
Random random= new Random();

// generates a number with upper limit 13
int random_face=random.nextInt(13);

// generated a number with upper limit 4
int random_suit=random.nextInt(4);
if(random_suit > 0){
this.suit=suit_values[random_suit-1];
}
else
{
this.suit=suit_values[0];
}
if(random_face > 0){
this.face=face_values[random_face-1];
}
else
{
this.face=face_values[random_face-1];
}

}
Card(int suitValue, int faceValue){
this.suit=suitValue;
this.face=faceValue;
}
int getFace()
{
return this.face;
}
String getFaceText()
{
return face_literals[this.face -1];
}
int getSuit()
{
return this.suit;
}
String getSuitText()
{
return suit_literals[this.suit -1];
}

public String toString()
{
return this.getFaceText() + " of "+ this.getSuitText();
}
public static void main(String args[])
{
//calling parametrized constructor
Card card= new Card(1,13);
System.out.println(card.getFace());
System.out.println(card.getFaceText());
System.out.println(card.getSuit());
System.out.println(card.getSuitText());
System.out.println(card);
  
//using default constructor
Card card1= new Card();
System.out.println(card1.getFace());
System.out.println(card1.getFaceText());
System.out.println(card1.getSuit());
System.out.println(card1.getSuitText());
System.out.println(card1);
}
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Introduction to Interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT