Need help with card and deck project

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dr4g0nk1ng
    New Member
    • Feb 2010
    • 1

    Need help with card and deck project

    i have this class that should create an array of cards

    Code:
    public class DeckOfCards{
      
      public Card card;
      public Card deck[];
      
      DeckOfCards() {
    
        for (int s = 0; s < 3; s++)
        {
          for (int i=0; i < 13; i++)
          {
            deck[i] = new Card(i,s);
            deck[i+13] = new Card(i,s);
            deck[i+26] = new Card(i,s);
            deck[i+39] = new Card(i,s);   
          }
        }
      }
      
      }
    this is the card

    Code:
    public class Card {
                                
        private final int suit;   
    
        private final int value;  
                                 
        public Card(int theValue, int theSuit) {
                
            value = theValue;
            suit = theSuit;
        }
            
        public int getSuit() {
              
            return suit;
        }
        
        public int getValue() {
               
            return value;
        }
      
        public String toString() {
    
            return getValue() + " of " + getSuit();
        }
    }
    how do i make a tester to display the deck

    that is what i was told to do
    . Provide a Class Card that knows it face value and suit value. Keep these as integers,

    2. The class must be able to translate its values to strings. (i.e. a face value of 13 will translate into King, a suit value of 1 may translate into Clubs).

    3. Provide a class DeckOfCards that will start out with 52 different cards. Create them in order. Use an array or array list to keep track of the cards.

    4. A DeckOfCards will return the top card when the deal() method is invoked.

    5. A DeckOfCards will know how many cards are still left in the deck.

    6. Provide a method to shuffle the cards in the deck. Swap the location of two random cards in the array and repeat this many times.

    7. Provide a driver that deals two cards, displays them and then asks the user whether s/he wants an additional card. Stop when the user says no.
    Last edited by dr4g0nk1ng; Feb 10 '10, 10:45 PM. Reason: miss info
  • pbrockway2
    Recognized Expert New Member
    • Nov 2007
    • 151

    #2
    how do i make a tester to display the deck
    Your DeckOfCards class could have a method to display the deck. A pair of nested for loops (like you use to populate the array) could work through the array and print each of the Card instances using their toString() method.

    Comment

    Working...