Results 1 to 3 of 3
  1. #1
    Exothesis is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default Return statement error

    For the following code, I get the error "missing return statement" at line 55.
    I have no idea what I am missing here.

    Java Code:
    public class Deck
    {
        private Card[] deck;
        private int cardsDealt;
    
        public Deck()
        {
            deck = new Card[52];
            int currentCard = 0;
    
            for(int suit = 1; suit <= 4; suit++)
            {
                for(int value = 1; value <= 13; value++)
                {
                    deck[currentCard] = new Card(value, suit);
                    currentCard++;
                }
            }
        }
    
        public void reset()
        {
            deck = new Card[52];
            int currentCard = 0;
    
            for(int suit = 1; suit <= 4; suit++)
            {
                for(int value = 1; value <= 13; value++)
                {
                    deck[currentCard] = new Card(value, suit);
                    currentCard++;
                }
            }
        }
    
        public Card getCard()
        {
            cardsDealt = 0;
            int rand = (int)(Math.random()*52);
    
            if(cardsDealt < 52)
            {
                if(deck[rand] != null)
                {
                    Card x = deck[rand];
                    deck[rand] = null;
                    cardsDealt++;
                    return x;
                }
                else
                {
                    return null;
                }
            }
        }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    What if cardsDealt is greater than or equal to 52? Even if not possible in your program, all possible branches of control of flow statements must result in a viable return statement.

  3. #3
    Exothesis is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

Similar Threads

  1. Return Statement and Boolean Help
    By GhostShaman in forum New To Java
    Replies: 8
    Last Post: 03-09-2010, 11:15 AM
  2. Missing Return Statement Error
    By darkblue24 in forum New To Java
    Replies: 13
    Last Post: 02-16-2010, 08:22 PM
  3. Replies: 5
    Last Post: 01-16-2010, 11:14 PM
  4. Missing Return Statement error
    By anilanar in forum New To Java
    Replies: 2
    Last Post: 08-20-2009, 01:02 AM
  5. there is no return statement
    By gabriel in forum New To Java
    Replies: 17
    Last Post: 12-03-2008, 04:55 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
  •