Context: I am trying to make a poker program that gives 5 cards from a deck of cards. I have a constructor that gives random cards and an array in a for loop that calls the constructor to give the user 5 cards. However i do not know how to set it up so that two cards do not have the same value && suit. So far I have tried putting a do/while loop in the for loop to no avail. This is part of the project:
The main class
public class pokerMain {
public static void main(String[] args) {
Scanner key = new Scanner(System.in);
pokerHand[] card = new pokerHand[5];
System.out.println("Would you like 5 random cards?");
if(key.next().equals("yes"))
{
for(int i = 0; i < 5; i++)
{
card[i] = new pokerHand();
System.out.println(card[i]);
}
}
}
}
and the class that contains the constructor
public class pokerHand {
private int value;
private String suit;
//gives a random card
public pokerHand()
{
Random card = new Random();
value = card.nextInt(13) + 1;
int suitNb = card.nextInt(4) + 1;
switch(suitNb)
{
case 1: suit = "hearts"; break;
case 2: suit = "spades"; break;
case 3: suit = "diamonds"; break;
case 4: suit = "clubs"; break;
}
}