Need Helps on Java Calculation Card Game


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: Need Helps on Java Calculation Card Game

  1. #1
    Join Date
    May 2006
    Posts
    10

    Need Help on Java Calculation Card Game

    Hello, I am new to learning java, and i am trying to build the class for a calculation card game, unfortunately i can't get the public Card top() and Card takeTop() method in the Stock class.
    Thanks!!
    -------------------------------------------
    this is the code for the Stock class:
    -------------------------------------------
    PHP Code:
    public class Stock
    {
        private 
    Deck deck = new Deck(52);
        private 
    int X;
        private 
    int Y;

        public 
    Stock(Deck deck)
        {
            
    this.deck deck;
        }
           
        
    /**
         * The number of cards in the stock(including the top card).
         * @return the number of cards.
         */
        
    public int numCardsRemaining()
        {
            return 
    deck.numCardsRemaining();
        }
        
      
        
    /**
         * The top card of the stock.
         * @return the top card of the stock, or null if the stock is empty.
         * Acall to this method does not remove the card from the top but 
         * just returns a reference to it.
         */

        
    public Card top()
        {
            if(
    deck.numCardsRemaining()==0)
            {
                return 
    null;
            }
            else
            {
                return 
    deck.cards.get(0);
            }

        }
        
        
    /**
         * Take the top card from the stock.
         * @return the card that was on top of the stock or null if the stock was empty.
         * A call to this method reduces the number of cards remaining in the    stock by one.
         */
        
    public Card takeTop()
        {

        }
            

    in order to solve the problems you need to know Deck class too, but we can't modify this class as assignment requires.

    -------------------------------------------
    The code for Deck class:
    -------------------------------------------

    PHP Code:
    import java.util.*;
    import java.awt.*;

    public class 
    Deck
    {
        private 
    java.util.List<Cardcards;      // The list of cards
        
    private static java.util.Random generator null;
        
        
    /**
         * Constructor for a shuffled deck of cards.
         * @param seed the seed for the random number generator used to
         * shuffle the deck. A different unique shuffle is obtained for
         * each possible value of seed.
         */
        
    public Deck(long seed)
        {
            
    // Create a deck of cards in sorted order of suit then pip count.
            
            
    cards = new ArrayList<Card>();
            for (
    int suit Card.SPADESsuit <= Card.CLUBSsuit++) {
                for (
    int pips 1pips <= Card.CARDS_IN_SUITpips++) {
                    
    cards.add(new Card(suitpips));
                }
            }
            
            
    // Now shuffle the deck, using a random number generator based
            // on the seed value given as a parameter.
            
            
    java.util.Random generator = new java.util.Random(seed); 
            
    java.util.Collections.shuffle(cardsgenerator);
        }
         
        public 
    int numCardsRemaining()
        {
            return 
    cards.size();
        }
        
        
    /**
         * Get the next card from the deck, reducing the number of cards
         * remaining in the deck by one.
         * @return the "top" card in the deck
         */
        
    public Card nextCard()
        {
            return 
    cards.remove(0);
        }
        
        
    /**
         * Add the given card to the start (front) of the current deck.
         * @param card the card to be placed at the start of the deck
         */
        
    public void addAtStart(Card card)
        {
            
    cards.add(0card);
        }
        
        
    /**
         * Add the given card to the end (back) of the current deck.
         * @param card the card to be placed on the end of the deck
         */
        
    public void addAtEnd(Card card)
        {
            
    cards.add(card);
        }

    ------------------------------------------------------------------
    so my problems are how to get public Card top() and public Card takeTop() methods in the Stock class without modify the Deck class.

    Thanks!
    Last edited by Lim; 05-21-2006 at 07:37 AM.

  2. #2
    Join Date
    May 2006
    Posts
    1
    Check you PMs.

  3. #3
    Join Date
    May 2006
    Posts
    10
    Hi there, Thank you very much that you can help me on my problems, Yes I do have the Card and FoundationRow class, as the code is too long, I made the code as a zip format.

    Thanks,
    Attached Files Attached Files
    Last edited by Lim; 05-15-2006 at 11:11 AM.

  4. #4
    Join Date
    May 2006
    Posts
    10
    Hi there,
    Here are the text format for the codes.
    Thanks!
    Attached Files Attached Files

  5. #5
    Join Date
    May 2006
    Posts
    10
    Iím still canít get the Card top() method working, I introduced a new variable topCard, which is store the value of deck.nextCard(), but when I return the topCard, this still not pass my test class.
    Can anyone help on me? Please!!

    Code:
        public Card top()
        {
            if(deck.numCardsRemaining()==0)
                {
                    return null;
                }
                else
                {
                    Card topCard = deck.nextCard();
                    deck.addAtStart(topCard);
                }
                return topCard;
            }
    Thanks.

  6. #6
    Join Date
    May 2006
    Posts
    11
    this is the requirements for the foundation row
    Attached Files Attached Files

  7. #7
    Join Date
    May 2006
    Posts
    11
    this is wat i get but still no passing stock test
    Attached Files Attached Files

  8. #8
    Join Date
    May 2006
    Posts
    10
    I figured it out now, check ur PMs.

  9. #9
    Join Date
    May 2006
    Posts
    4
    im doing this assignment 2, so can u share some information with me pls like as stock, foundationrow, foundation otherwise ill share u too, if u want, thx bro a lot.

  10. #10
    Join Date
    May 2006
    Posts
    5
    Hi,
    Could one of you people help me as Im stuck on the foundationRow class question.

    Any help is appreciated, thanks.

  11. #11
    Join Date
    May 2006
    Posts
    4
    /** Constructor for objects of class FoundationRow that will not be
    * displayed graphically
    **/
    Card[] cards;
    Deck deck;
    Card cardStart=null;
    //int startNumber=0;
    public FoundationRow(int startNumber, Deck deck)
    {
    this.deck = deck;
    cards = new Card[13];
    while(this.deck.numCardsRemaining()>0)
    {
    cardStart = this.deck.nextCard();
    if(cardStart.getNumber()==startNumber)
    {
    cards[0] = cardStart;
    break;
    }
    else
    this.deck.addAtEnd(cardStart);
    }
    //cards[0].cardNumPips = startNumber;
    for(int i=1; i<13; i++)
    {
    cards[i]=null;
    }

    //cards[0] = deck.nextCard();
    }

  12. #12
    Join Date
    May 2006
    Posts
    5
    Ive already got the constructor for FOundationRow, I am stuck on the getCards() method. It doesn't pass the unit test at all

    Bah, only got one day to hand this in. Looks like I'll be up all night tonight working on this
    Last edited by BillyBob; 05-24-2006 at 03:30 AM.

  13. #13
    Join Date
    May 2006
    Posts
    5
    Oops I meant to write, I am stuck on the putCard method

  14. #14
    Join Date
    May 2006
    Posts
    4
    can u just share 4 me the constructor pls, i can'nt fiure out it? thx, ill do the putcard method soon to post in here

  15. #15
    Join Date
    May 2006
    Posts
    5
    I haven't fully figured out the constructor as it only passes the first two tests and fails the third one.

Similar Threads

  1. Java card development kit
    By talk2esta in forum Java
    Replies: 3
    Last Post: 09-23-2005, 12:24 PM
  2. Java checkers game?
    By kikkoman in forum Java
    Replies: 1
    Last Post: 09-15-2005, 04:43 PM
  3. Java game upload for Nec e606
    By romulan in forum Mobile
    Replies: 0
    Last Post: 06-23-2003, 03:21 PM
  4. Replies: 0
    Last Post: 02-01-2002, 12:08 AM
  5. Snake game On-Line. Free java sources.
    By Alex in forum web.announcements
    Replies: 0
    Last Post: 08-09-2001, 04:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center