0

Deck of cards(Help with Homework)

The program should create an array of 52 cards (the normal deck of cards), shuffle them, then print them. I'm stuck. public class Card { class Card { int suit, rank; public Card() { this.suit = 0; this.rank = 0; } public Card(int suit, int rank) { this.suit = suit; this.rank = rank; } } public static void printCard(Card c) { String[] suits = {"Clubs", "Diamonds", "Hearts", "Spades"}; String[] ranks = { "narf", "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"}; System.out.println(ranks[c.rank] + " of " + suits[c.suit]); } public static void main(String[] args) { } }

26th Nov 2017, 1:34 AM
Geena Nana
Geena Nana - avatar
1 ответ
+ 3
In main put two loops to create cards: for (int suit = 0; suit < 4; suit++) for (int rank = 1; rank < 14; rank++) Card card = new Card(suit, rank); You need a place to store the cards so you can shuffle them and print. Personally, a Deck class using a: Card deck[52]; It needs to shuffle with a method. I'd use 156 (three decks) pairs of random numbers. Switch the two cards selected by the random numbers.
26th Nov 2017, 2:01 AM
John Wells
John Wells - avatar