Question: I need help to shuffle cards dynamically using the same array, NO ARRAYLISTS,NO ENUM,NO COLLECTIONS CLASS!!!!!! Here's my code Card: public class Card2 { private
I need help to shuffle cards dynamically using the same array, NO ARRAYLISTS,NO ENUM,NO COLLECTIONS CLASS!!!!!!
Here's my code
Card:
public class Card2 { private int rank; private int suit; /* / Constructer for creating a Card */ public Card2(int r,int s) { if(rank>=2||rank<=10) { this.rank = r; // examines the current rank of card. this.suit = s; // examines the current suit of card. } } /* / Method for getting the Rank of the Card. */ public int getRank() { return rank; // returns the rank. } /* / Method for getting The Suit of the Card. */ public int getSuit() { return suit; // returns the card suit; } @Override public String toString() // returns the String representation of // the Crad with the Ran and Suit Combine. { String r = "",s = ""; if(rank>=2 && rank<=10) { r = rank+""; } else if(rank == 11) { r="J"; } else if(rank == 12) { r = "Q"; } else if(rank == 13) r = "K"; else if(rank == 14) r = "A"; switch(suit) { case 1: s = "\u2660"; break; case 2: s = "\u2665"; break; case 3: s = "\u2663"; break; case 4: s = "\u2666"; break; } return r + s; // returns String representation of card. } }
Deck class:
public class Deck2 { private Card2 [] deck; private final int numCards = 52; Random rand = new Random(); Card2 c; int r; int s; public Deck2(){ deck = new Card2[numCards]; int i = 0; for(int r = 2;r<15;r++) { for(s = 1;s<5;s++) { deck[i]= new Card2(r,s); i++; } } } public Card2[] shuffleTheseCards() { Card2 c1 = deck[numCards]; for(int i = 0;i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
