import java.util.Random;
public class CardDeck
{
 private String deck[] = new String[52];
 private String shapes[] = {"heart", "club", "spade", "diamond"};
 private String numbers[] = {"ace", "deuce", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "jack", "queen", "king"};
 public void CreateDeck()
 {
  for(int s =0; s < shapes.length; s++)
  {
   for(int n=0; n<numbers.length;n++)
   {
    deck[s*13+n] = shapes[s] + " " + numbers[n];
   }
  }
 }
 public void Shuffle()
 {
  Random r = new Random();
  int loc1, loc2;
  for(int i=0; i<1000;i++)
  {
   loc1 = r.nextInt(52);
   loc2 = r.nextInt(52);
   String tmp = deck[loc1];
   deck[loc1] = deck[loc2];
   deck[loc2] = tmp;
  }
 }
 public void DealCards()
 {
  for (int i = 0; i < 5; i++)
  {
   System.out.println(deck[i]);
  }
 }
}

I've been thinking over this problem for the whole weekends, and still figuring out on HOW CAN I BREAK DOWN THE deck[] so that I can read what is the number of the card and the suit it has? :( I'm really confused! Thanx so much!!!!

Do some adjustment to your random generator that is generate number between 0 to 51(inclusive). Store values in array, when new value generated compare with array if already exist. If doesn't exist store it in array, else generate new number
To get a card, here is pseudo code ( assuming that arra deck holds generated numbers )

if(deck[i]>= 0 && deck[i] < 13)
{
    shapes[0]
    numbers[deck[i] ]
}
else if(deck[i]>12 && deck[i] < 26)
{
    shapes[1]
    numbers[deck[i] - 13 ]
}
else if(deck[i]>25 && deck[i] < 39)
{
    shapes[2]
    numbers[deck[i] - 26 ]
}
else if(deck[i]>38 && deck[i] < 52)
{
    shapes[3]
    numbers[deck[i] - 39 ]
}

Hope, this is what you wanted

but the thing that you said will only compare the card that I have, I want to know whether the card face, or the numbers is the same. Random generator will only randomly shuffle the card that already generated with both face and numbers... :-/ I need to know whether it's two pairs, three pairs, flush, whatever else... :-/

To break down the deck[] element to get back the face and shape, you can do something like:

// Assuming the face and shape are seperated by a space
int space = deck[i].indexOf (' ') ; 
String shape = deck[i].substring (0, space) ;
String face = deck[i].substring (space + 1, deck[i].length()) ;

but the thing that you said will only compare the card that I have, I want to know whether the card face, or the numbers is the same. Random generator will only randomly shuffle the card that already generated with both face and numbers... :-/ I need to know whether it's two pairs, three pairs, flush, whatever else... :-/

That is what happends if you do not take time to explain what you want ;)

Member Avatar for iamthwee

To break down the deck[] element to get back the face and shape, you can do something like:

// Assuming the face and shape are seperated by a space
int space = deck[i].indexOf (' ') ; 
String shape = deck[i].substring (0, space) ;
String face = deck[i].substring (space + 1, deck[i].length()) ;

Well he/she shouldn't be concatenating the "shape" and "numbers" into a string in the first place. That would defeat the whole purpose of object orientated programming - that must be what their teacher is expecting. What he/she is lacking is basic methods in their class.

card[i].getShape
card[i].getNumber

Maybe yes, but given the imcomplete problem statement, getting to the actual requirements is kind of guesswork. The best we can do is guide him in what he is asking. The abstraction touch would be too much for the OP.

i need some help on card game. need to get it working before monday the 21 of may.. any help will be better than nothing

cheers

The objective of this exercise is for you to write a straightforward Java program, exhibiting your skills
in object oriented and structured programming.
The aim of the program you will write is to discover the probability that a game of clock patience will
‘come out’. Clock patience is played by a single player using a standard pack of 52 playing cards. In
a pack there are four suits, Hearts, Clubs, Diamonds and Spades, and each suit comprises cards valued
from 1 to 13 (Jack = 11, Queen = 12, King = 13, Ace = 1). To begin clock patience the shued pack is
dealt, face down, into 13 piles of 4 cards each. The first 12 piles are arranged in a circle at the 12 hour
positions on a clock and the 13th (corresponding to kings) is placed in the middle.
Play then proceeds by turning up the card on the top of the 12 O’clock pile. Suppose its value is 5, then
it is placed (faced up) at the bottom of the 5 O’clock pile. Then top card of the 5 O’clock pile is turned
up and the same procedure followed (e.g., if it is a Jack then it is put face up on the bottom of the 11
O’clock pile and the top card of the 11 O’clock pile turned over). Play stops when the pile in the middle
consists of all the kings, face up. If all the cards in any other pile have been turned over, then the top
card of the next highest valued pile is turned over instead.
The aim of the game is to finish each card in the pile corresponding to its value. However, frequently all
the kings are turned up but there are still cards face down in the remaining piles; call the total number
of cards remaining face down the ‘residue’ (i.e., a successful game corresponds to a residue of zero).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.