For this project your card class must include an Image of th
For this project your card class must include an Image of the card. Here is a zip filecontaining 52 images you can use for your cards. Please note that the name for each card can be created by the concatenation of the first character of the suit, the value of the card, and the \".png\" suffix. When you construct a card, you should have it load its image. Alternatives exist regarding how to draw() the card. One way to do this is to have a location (x,y coordinates) associated with a card and a method that asks the card to draw itself. A second way is to have the dealer decide where to place the cards. You will need to make a design decision regarding which method to employ, and you will write and submit a paragraph to describe why you chose the policy you chose. DeckOfCards Class The DeckOfCards class is unchanged from project 2. CardPanel Class We now need a CardPanel class that extends the JPanel class upon which the hands will be drawn when they are dealt. GameViewer Class This is the driver for our application. It will contain an instance of the JFrame class or extend the class. It will include a \"main\" method. We will discuss how to extend the JFrame class to build a GUI application. For this project we will include only a single menu (Game) and it will have two options (About, Exit). About should pop up a dialog that has a short paragraph about the game, and Exit will quit.. Here are the primary tasks done by the GameViewer Initialize the JFrame (size, location, defaultClose, etc.). Create a deck of cards. Create a [DealPoker] button with an ActionListener Create a [DealBridge] button with an ActionListener Create a cardPanel object with the buttons. Create the menu and menuItems. Deal two hands of 5 cards each when the DealPoker button is clicked. Deal the entire deck into 4 hands when the DealBridge button is clicked. The controller must keep track of how many cards are left in the case of dealing Poker (via the size() method in DeckOfCards) and when there are not enough to deal a new hand, create a new deck. The program should get a new deck each time a bridge hand is dealt. Background Reading: Graphics and GUIs General Project Requirements: Submit all source files required by your application (as a single zip file): Card.java DeckOfCards.java CardPanel.java GameViewer.java Your .jpg files of the cards you use Do not submit any .class files. Do not include tabs in your projects. Use spaces only. Let jGrasp or Eclipse do that for you. Document all classes and all methods using JavaDoc comments.
Solution
import java.util.Random;
public class DeckOfCard {
private Card cards[];
/*Size of the deck which can handle cards*/
private int size;
private Suit suits[];
private Value values[];
public DeckOfCard(){
size=52;
currentCount=0;
cards = new Card[size];
suits=Suit.values();
values=Value.values();
for(int i =0 ; i<suits.length;i++){
for(int j =0 ; j<values.length;j++){
cards[currentCount++] = new Card(suits[i],values[j]);
}
}
}
/*This is to shuffle the cards in the deck with the remaining cards.
Variable numberOftime represents the number of time need to shuffle the cards in deck*/
public void shuffle(int numberOftime){
Random rand= new Random();
for(int i=0;i<numberOftime;i++){
int m=rand.nextInt(currentCount);
int n=rand.nextInt(currentCount);
Card temp=cards[m];
cards[m]=cards[n];
cards[n]=temp;
}
}
/*This function is to deal the cards whatever is on top of the deck.*/
public void deal(){
System.out.println(cards[--currentCount]);
}
/*This is to represents the String representation of the current cards inthe deck.*/
public String toString(){
StringBuilder sb=new StringBuilder();
for(int i=0;i < currentCount;i++){
sb.append(cards[i]);
sb.append(\" \");
}
return sb.toString();
}
/* Sorting the cards based on the suit and then numbers.
This sorting is using Bucket Sort to sort the cards runtime= O(n) space=O(n);*/
public void sort(){
Card bucketCards[][]= new Card[suits.length][values.length];
for(int i=0;i<currentCount;i++){
bucketCards[cards[i].getSuit().ordinal()][cards[i].getValue().ordinal()]=cards[i];
}
int pointer=0;
for(int i=0;i<suits.length;i++){
for(int j=0;j<values.length;j++){
if(bucketCards[i][j]!=null)
cards[pointer++]=bucketCards[i][j];
}
}
}
/*This will reset the deck. i.e it will put back all the cards in the deck if it has been dealt.*/
public void resetdesk(){
currentCount=52;
}
/*Printing the stack of cards in format*/
public void printStack(){
int cardPointer=0;
for(int i=0;i<suits.length;i++){
for(int j=0;j<values.length;j++){
System.out.print(cards[cardPointer++]+\" \");
}
System.out.println(\"\ \");
}
}
/*Get size of the deck*/
public int getSize() {
return size;
}
/*This represents the suit of the card*/
private enum Suit{
CLUB,DIAMOND,SPADE,HEART
}
/* This represents the number of the card*/
private enum Value{
ACE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN,JACK,QUEEN,KING
}
/* This class represents the card with specific suit and value.
* Cannot change the value once instansiated */
private class Card{
private final Suit suit;
private final Value value;
public Card(Suit suit, Value value){
this.suit=suit;
this.value=value;
}
public Suit getSuit() {
return suit;
}
public Value getValue() {
return value;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return suit+\"-\"+value;
}
}
}


