I am working on a project to create a poker game. Although the instructions are pretty clear, I have so many problems with object oriented programming.
So, for this project we need to create four objects: Card, Deck, Hand and Poker Hand. I have already finished creating the card object, and now I am working on the deck object. This is the area in which I have problems right now. I tried to deal with my problem. However, since I am so new to programming, I really don't get their methods. For example, I do not know how to use ArrayList. I know only the basic methods of the array.
The following code is what I have done so far for the Deck object:
import java.util.*;
public class Deck {
public static final int CARDS_IN_DECK = 52;
public static final int SHUFFLE_SWAPS = 700;
int shufflex = 0;
private Card[] cards;
private int card_holder;
private int seed;
public Deck(int seed) {
this.cards = new Card[CARDS_IN_DECK];
seed = 0;
for (int i = 2; i <= 14; i++) {
for (int j = 0; j <= 3; j++) {
if (j == 0) {
cards[seed] = new Card(i, 'c');
} else if (j == 1) {
cards[seed] = new Card(i, 'd');
} else if (j == 2) {
cards[seed] = new Card(i, 's');
} else if (j == 3) {
cards[seed] = new Card(i, 'h');
}
seed++;
}
}
}
public void shuffle(){
Random rand = new Random ();
int randomNumber = rand.nextInt(51);
int randomNumber2 = rand.nextInt(51);
while( shufflex < SHUFFLE_SWAPS ){
HOW DO I DO THE SWAP HERE? DON'T KNOW THE SYNTAX
I KNOW I NEED TO CREATE ANOTHER ARRAY TO TEMPORARY STORE THE FIRST CARD
THEN I REPLACE THE FIRST CARD WITH THE SECOND CARD
AND THEN REPLACE THE SECOND CARD WITH THE TEMPORARY CARD
shufflex++;
}
}
public Card nextCard() {
}
public String toString() {
}
}
And here are the descriptions for this part:
Deck 52 . .
, Deck. .
:
CARDS_IN_DECK - . 52.
SHUFFLE_SWAPS - , . , . 500.
:
, CARDS_IN_DECK . .
, , . 0 1 (. ).
, , .
, .
public Deck(int seed) - Deck. , 52 , "CARDS_IN_DECK". . ( 2-14 ), . seed .
. Card.CLUBS, Card.LOWEST_VALUE .. .
public void shuffle() - . , Random . 0-51. . , 20 11, 2 20 , 3 11 , , , 20 3 11 2 . , "SHUFFLE_SWAPS" , . -1, . , , . ,
Random rand = new Random(seed);
-1, , , . ,
Random rand = new Random();
, , , , reset 0.
public Card nextCard() - , , , . , , , ( 1).
public String toString() - , Unit Testing. : toString() Card .
, public Deck (int seed). ? (int value, char suit), (int, char). , . -, , ?