Question: 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

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. In Java Pls

Assignment 4 Code:

import java.util.Random;

class Card{ //class Card

int suit;

int face;

public Card(){ //default constructor

Random rand = new Random();

//assingning random values in the specified range

int suit = rand.nextInt(4)+1;

int face = rand.nextInt(13)+1;

this.suit=suit;

this.face=face;

} public Card(int face,int suit){ //parameterised constructor //it sets the value only if the values are in the specified range if(suit>=1 && suit<=4) this.suit=suit; if(face>=1 && face<=13) this.face=face;

}

int getFace(){

return face;

}

int getSuit(){

return suit;

}

void setFace(int fac){

if(fac>=1 && fac<=13){

this.face=fac;

}

}

void setSuit(int s){

if(s>=1 && s<=4)

this.suit=s;

}

String getFaceText(){ //return the text of face

String[] faces={" ","Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"};

return faces[face];

}

public String toString()

{

String[] faces={" ","Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"};

String[] suits={" ","Hearts","Clubs","Diamonds","Spades"};

String faceStr = (face != 0) ? faces[face] : "invalid";

String suitStr = (suit!= 0) ? suits[suit] : "invalid";

return faceStr + " of " + suitStr;

}

}

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!