Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static ArrayList<Card> createDeck(){
- ArrayList<Card> deck = new ArrayList<>();
- int i = 0; //Used to limit the number of the cards below 14 (i.e. Ace)
- int j = 0; //Used to keep the total number of cards below 52
- int k = 0; //Temporary variable used to increment J, and make sure there are only 4 of each card face
- int l = 0; //Used to assign the suit of the card
- for(;i < 14;i++){
- for(;j<(k+4) && j < 52;j++){
- deck.add(new Card((l+1),(int)(Math.floor(j/4)+2))); //Adds a new Card to the array with the suit, then the number of the card.
- System.out.println((j+1) + ":" + deck.get(i).getName() + ":" + deck.get(i).getSuit()); //<1>
- l++;
- }
- l = 0;
- k = j;
- }
- return deck;
- }
- }
- public static void main(String[] args){
- ArrayList<Card> deck = new ArrayList<>();
- deck = Card.createDeck();
- for(int i = 0; i < 52;i++){
- System.out.println(deck.get(i).getName() + ":" + deck.get(i).getSuit()); //<2>
- }
- }
- /**
- * Sample output from <1>:
- * 1:2:Hearts
- * 2:2:Diamonds
- * 3:2:Clubs
- * etc.
- **/
- /**
- * Sample output from <2>:
- * Ace:Spades
- * Ace:Spades
- * Ace:Spades
- * etc.
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement