feedback

(Solution document) i am having trouble filling out the shuffle method for this class... i am trying to build a game of blackjack. can someone please help me create the


i am having trouble filling out the shuffle method for this class... i am trying to build a game of blackjack. can someone please help me create the method? i am stuck..




package blackjacktest;


import java.util.ArrayList;

import java.util.Random;

//deck of 52 Anglo-American playing cards.




public class Deck  //extends class BlackJackTest;


{

  /** 

   * The cards are stored in a linked-list implementation of the

   * List collection.

   */

  private ArrayList cards;

  //String new ArrayList=["2 ","3 ","4 ","5 ","6 ","7 ","8 ","9 ","10 ","J ","Q ","K ","A"}];

   

  /** Lowest ranking card (the ace). */

  private static final int ACE = 1;

   

  /** Highest ranking card (the king). */

  private static final int KING = 13;

   

  /** 

   * Total number cards in the deck (4 suits, each with 13 cards of 

   * different ranks).

   */ 

  //Constructs - new deck

  private static final int TOTAL_CARDS = 52;

   

  /** 

   * Some constants that define the Strings for the various suits.

   */ 

  private static final String HEARTS = "hearts";

  private static final String DIAMONDS = "diamonds";

  private static final String CLUBS = "clubs";

  private static final String SPADES = "spades";

   

  private int size;

  

  public Deck()

  {

    cards = new ArrayList ();

    String []ArrayList ={"2 ","3 ","4 ","5 ","6 ","7 ","8 ","9 ","10 ","J ","Q ","K ","A"};

     

     

    buildSuit(HEARTS);

    buildSuit(DIAMONDS);

    buildSuit(CLUBS);

    buildSuit(SPADES);

     

    System.out.print ("card");

  }

  //suit

    private void buildSuit(String suit)

  {

    for(int i = ACE;i<=KING;i++) {

      ArrayList add;

      add = cards.add(new Card(suit,i));

       

    }

  }

 

  // Shuffles 

   

  /*public void shuffle()

  {  

    //Shuffle

    Random rgen = new Random();

    int []Cards =new int [52];

    

    for (int i = 0; i

      {

        cards[i]=i;

      }

     for (int i=0; i

     int randomPosition = r.nextInt(cards.length);

     int temp = cards[i];

    cards[i] = cards[randomPosition];

    cards[randomPosition] = temp;

    } 

      

    }

*/

  public Card dealCard()

  {  int size;

    this.size = this.size - 1;

    if (this.size > 0) 

    {

      return this.cards.get(this.size);

    }

    return null;

  }

 

  /**

   * Determines if this deck is empty.

   * @return 

   */

  public boolean isEmpty()

  {

    return(cards.isEmpty());

  }

  

   

  //Returns the number of cards that are currently in the deck.

  

   public int size()

  {

    return cards.size();

  }


  // private void println(String card) {

    // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

   


  //private void print(String card) {

    // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

   

}

 







About this question:

Pay using PayPal (No PayPal account Required) or your credit card. All your purchases are securely protected by .
SiteLock