I am trying to create a program that would deal out two cards out of a deck of 52 cards. So far, I have used a switch statement to assign card values to a number, Ace of Spades = 0, Seven of Clubs = 26 for example. However, in order to have two cards, they must be unique and I'm not sure how to go about that.
import java.lang.Object;
import java.util.Scanner;
import java.util.Random;
public class Deck {
public static void main(String[] args) {
Random rnd = new Random();
int cardNumber = rnd.nextInt(52);
String toCard = null;
switch (cardNumber){
case 0: toCard = "Ace of Spades";
break;
case 1: toCard = "Ace of Hearts";
break;
case 2: toCard = "Ace of Clubs";
break;
case 3: toCard = "Ace of Diamonds";
break;
case 4: toCard = "Two of Spades";
break;
case 5: toCard = "Two of Hearts";
break;
case 6: toCard = "Two of Clubs";
break;
case 7: toCard = "Two of Diamonds";
break;
case 8: toCard = "Three of Spades";
break;
case 9: toCard = "Three of Hearts";
break;
case 10: toCard = "Three of Clubs";
break;
case 11: toCard = "Three of Diamonds";
break;
case 12: toCard = "Four of Spades";
break;
case 13: toCard = "Four of Hearts";
break;
case 14: toCard = "Four of Clubs";
break;
case 15: toCard = "Four of Diamonds";
break;
case 16: toCard = "Five of Spades";
break;
case 17: toCard = "Five of Hearts";
break;
case 18: toCard = "Five of Clubs";
break;
case 19: toCard = "Five of Diamonds";
break;
case 20: toCard = "Six of Spades";
break;
case 21: toCard = "Six of Hearts";
break;
case 22: toCard = "Six of Clubs";
break;
case 23: toCard = "Six of Diamonds";
break;
case 24: toCard = "Seven of Spades";
break;
case 25: toCard = "Seven of Hearts";
break;
case 26: toCard = "Seven of Clubs";
break;
case 27: toCard = "Seven of Diamonds";
break;
case 28: toCard = "Eight of Spades";
break;
case 29: toCard = "Eight of Hearts";
break;
case 30: toCard = "Eight of Clubs";
break;
case 31: toCard = "Eight of Diamonds";
break;
case 32: toCard = "Nine of Spades";
break;
case 33: toCard = "Nine of Hearts";
break;
case 34: toCard = "Nine of Clubs";
break;
case 35: toCard = "Nine of Diamonds";
break;
case 36: toCard = "Ten of Spades";
break;
case 37: toCard = "Ten of Hearts";
break;
case 38: toCard = "Ten of Clubs";
break;
case 39: toCard = "Ten of Diamonds";
break;
case 40: toCard = "Jack of Spades";
break;
case 41: toCard = "Jack of Hearts";
break;
case 42: toCard = "Jack of Clubs";
break;
case 43: toCard = "Jack of Diamonds";
break;
case 44: toCard = "Queen of Spades";
break;
case 45: toCard = "Queen of Hearts";
break;
case 46: toCard = "Queen of Clubs";
break;
case 47: toCard = "Queen of Diamonds";
break;
case 48: toCard = "King of Spades";
break;
case 49: toCard = "King of Hearts";
break;
case 50: toCard = "King of Clubs";
break;
case 51: toCard = "King of Diamonds";
break;
}
System.out.println(cardNumber + " " + toCard);
}
}
I know that there's probably many more efficient ways of approaching this but I'm relatively new to coding in general. I want to assign each of the cases to an index in an array so that I can call say cardArray[0] and return Ace of Spades, and eventually call two random numbers from the cardArray and have them be unique cards.
Any help is appreciated.