Question

For this project your card class must include an Image of the card. Here is a...

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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("\n");
}

}

/*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;
}
}
}

Add a comment
Know the answer?
Add Answer to:
For this project your card class must include an Image of the card. Here is a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Given these three classes: Card, DeckOfCards, and DeckOfCardsTest. Extend the DeckofCards class to implement a BlackJack...

    Given these three classes: Card, DeckOfCards, and DeckOfCardsTest. Extend the DeckofCards class to implement a BlackJack class, which implements a BlackJack game. Please do not use any java applet on the coding. Hint: Use a test class to test above classes. Pulic class Card {    private final String face; // face of card ("Ace", "Deuce", ...)    private final String suit; // suit of card ("Hearts", "Diamonds", ...)    // two-argument constructor initializes card's face and suit    public...

  • NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET...

    NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET CODE TO RUN!! THANKS Extend the DeckofCards and the Card class in the book to implement a card game application such as BlackJack, Texas poker or others. Your game should support multiple players (up to 5 for BlackJack). You must build your game based on the Cards and DeckofCards class from the book. You need to implement the logic of the game. You can...

  • Computer Science 182 Data Structures and Program Design Programming Project #3 – Link List Card Games...

    Computer Science 182 Data Structures and Program Design Programming Project #3 – Link List Card Games One of the nice things about Java is it is very easy to do fun things with graphics. The start code provided here will display a deck of cards on the screen and shuffle them. Your mission, is to start with this code and build a card game. Blackjack, poker solitaire, what ever your heart desires. Blackjack is the easiest. Obviously any program you...

  • *in Java 1. Create a card class with two attributes, suit and rank. 2.In the card...

    *in Java 1. Create a card class with two attributes, suit and rank. 2.In the card class, create several methods: a. createDeck – input what type of deck (bridge or pinochle) is to be created and output an array of either 52 or 48 cards. b.shuffleDeck – input an unshuffled deck array and return a shuffled one. + Create a swap method to help shuffle the deck c. countBridgePoints – inputs a 13-card bridge ‘hand’-array and returns the number of...

  • Write a class named Card which will represent a card from a deck of cards. A...

    Write a class named Card which will represent a card from a deck of cards. A card has a suit and a face value. Suits are in order from low to high: Clubs, Diamonds, Hearts and Spades. The card values from low to high: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, and Ace. Write a Deck class that contains 52 cards. The class needs a method named shuffle that randomly shuffles the cards in the...

  • CS102 : JAVA Object-Oriented Programming. 1 Write a class Card whose instances represent a single playing...

    CS102 : JAVA Object-Oriented Programming. 1 Write a class Card whose instances represent a single playing card from a deck of cards. Playing cards have two distinguishing properties an integer for the rank (1 (corresponding to Ace) ,2,3, 13 (correspond ing to King) and suit (Spades, Hearts, Diamonds, or Clubs). Make the suit an enumerated data type. Include getters and setters and a method that tests if a card is valid. Write a class named Deck whose instances are full...

  • IN JAVA - COMMENT CODE WELL Write a class named Card which will represent a card...

    IN JAVA - COMMENT CODE WELL Write a class named Card which will represent a card from a deck of cards. A card has a suit and a face value. Suits are in order from low to high: Clubs, Diamonds, Hearts and Spades. The card values from low to high: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, and Ace. Write a Deck class that contains 52 cards. The class needs a method named shuffle that...

  • In the last assignment, you created a card class. Modify the card class so the setValue()...

    In the last assignment, you created a card class. Modify the card class so the setValue() method does not allow a card’s value to be less than 1 or higher than 13. If the argument to setValue() is out of range, assign 1 to the card’s value. You also created a PickTwoCards application that randomly selects two playing cards and displays their values. In that application, all card objects were arbitrarily assigned a suit represented by a single character, but...

  • I've created a Card class and I'm asked to implement a class called DeckOfCards that stores...

    I've created a Card class and I'm asked to implement a class called DeckOfCards that stores 52 objects of the Card class. It says to include methods to shuffle the deck, deal a card, and report 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. I also need to create a separate driver class that first outputs the populated deck to prove it...

  • How do you do this using visual studio on a Mac? You are tasked with creating...

    How do you do this using visual studio on a Mac? You are tasked with creating an application with five PictureBox controls. In the Poker Large folder, you will find JPEG image files for a complete deck of poker cards. Feel free to choose any card image that you like or be creative with this application. Each PictureBox should display a different card from the set of images. When the user clicks any of the PictureBox controls, the name of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT