You will have three separate, or internal classes that will: Instantiate a Card Instantiate a Deck of
Question:
You will have three separate, or internal classes that will:
- Instantiate a Card
- Instantiate a Deck of those Cards, and shuffle and deal them.
- Play the game.
In this project you will simulate the playing of a simple card game. You are given a Card and Deck class to use. The Card class should not be changed or renamed, I will use my own Card class when testing your files.
This assignment should be submitted in two classes; Main+lastName, Deck+lastName, or using internal declared classes, but will not be referenced in this manner henceforth. The first class, Deck, will be a modification of the class I have provided. You will need to implement the shuffleDeck method in order for this class to be usable, which has already been written for you in a method.
The second class, Main, will use the Card class and your modified Deck class to create a shuffled Deck object and deal the two hands. The hands should be dealt in alternating order, starting with the first hand. As the cards are dealt into each hand they should be removed from the deck.
For example, each hand is shown for the following Deck.
seven of spades <-- Index 0, top card
queen of spades <-- Index 1, etc.
ten of spades
eight of spades
three of spades
king of hearts
queen of hearts
jack of clubs
four of clubs
eight of clubs
king of diamonds
seven of hearts
Hand 1: | Hand 2: | |
seven of spades | queen of spades | |
ten of spades | eight of spades | |
three of spades | king of hearts | |
queen of hearts | jack of clubs | |
four of clubs | eight of clubs |
Each of these cards should be removed from the deck.
After dealing the hand, Main should use the point value attribute of each card to calculate the total point value of each hand. The hand with the highest point value wins. In the case of a draw, the second hand wins. In this game ace = 1, jack = 11, queen = 12, and king = 13. In the deck the card in the first position (index 0) is the top of the deck.
Lastly, Main will declare the winning hand. See the following sample run for the exact format that will be expected.
Sample Run of Main:
Hand 1: Total points 22
three of clubs (point value = 3)
two of clubs (point value = 2)
six of hearts (point value = 6)
ten of hearts (point value = 10)
ace of spades (point value = 1)
Hand 2: Total points 27
four of spades (point value = 4)
ten of clubs (point value = 10)
three of diamonds (point value = 3)
eight of diamonds (point value = 8)
two of hearts (point value = 2)
Hand 2 wins
Play again (y/n)?
To plan for the program, you should review the given classes. Knowing which methods are available to you will be very helpful in designing your game. Then, you should plan the algorithms that you will design.
Use the following table to plan your program.
Card/Deck Methods & Variables | Main |
Card - Methods & Variables
Deck - Methods & Variables
| Main.main
|
You do NOT need to hand in Card, nor customize the class or the instantiation usage of Card in Deck or Main! But you still need to change Deck and Main to include your last name.
Part 1.
/*
* Shuffle Deck Class
* A class which represents a Deck of cards. For this assignment, you will need to
implement the method shuffleDeck,
* which appears at the bottom of this class.
*/
import java.util.ArrayList;
public class Deck {
/* Your code goes here */
}
//SHUFFLE **************************** DO NOT EDIT BELOW!
**********************************
//You will need to implement the shuffleDeck method in order for this class to
be accepted.
public ArrayList shuffleDeck ()
{
ArrayList t = new ArrayList ();
int i = 0;
int n [] = new int [52];
for (int j = 0; j < 52; j++){
i = (int)(Math.random()*52);
while (n[i] != 0)
i = (int)(Math.random()*52);
n[i] = 1;
t.add(deck.get(i));
}
return t;
}
}
part 2.
/*
The second class, Main, will use the Card class and your modified Deck class to
create a shuffled Deck object and deal the two hands.
The hands should be dealt in alternating order, starting with the first hand. As
the cards are dealt into each hand they should be removed from the deck.
For example, each hand is shown for the following Deck.
seven of spades <---- Index 0, top card
queen of spades <---- Index 1, etc.
ten of spades
eight of spades
three of spades
king of hearts
queen of hearts
jack of clubs
four of clubs
eight of clubs
king of diamonds
seven of hearts
Hand 1: Hand 2:
seven of spades queen of spades
ten of spades eight of spades
three of spades king of hearts
queen of hearts jack of clubs
four of clubs eight of clubs
Also, all of these cards should be removed from the deck
After dealing the hand, Main should use the point value of each card to calculate
the total point value of each hand.
The hand with the highest point value wins. In the case of a draw, the second hand
wins. In this game ace = 1, jack = 11, queen = 12, and king = 13.
In the deck the card in the first position (index 0) is the top of the deck.
Lastly, Main will declare the winning hand. See the following sample run of Main
for the exact format that will be expected by the code-runner.
Sample Run of Main:
Hand 1: total points 22
three of clubs (point value = 3)
two of clubs (point value = 2)
six of hearts (point value = 6)
ten of hearts (point value = 10)
ace of spades (point value = 1)
Hand 2: total points 27
four of spades (point value = 4)
ten of clubs (point value = 10)
three of diamonds (point value = 3)
eight of diamonds (point value = 8)
two of hearts (point value = 2)
Hand 2 wins
*/
import java.io.IOException;
import java.util.ArrayList;
public class Main{
public static void main(String str[]) throws IOException{
}
Note:- Make sure the Deck and Main are well documented/commented.
It is time to show off all of your incredible talent and all that you have learned by programming a simple card game, we will use the concept of poker, but without actual cards.