Results 1 to 7 of 7

Thread: [Java] Going over code/logic for blackjack

  1. #1
    Join Date
    Jul 2013
    Beans
    8

    [Java] Going over code/logic for blackjack

    Hi,

    I'm working on an assignment for a blackjack game and I need some help figuring out how to fix an Exception error: "java.lang.ArrayIndexOutOfBoundsException: 52" which has something to do with the shuffle(). I think I implemented it correctly, but maybe there is something I'm not seeing?

    Hopefully someone can help me out?
    Note 1: For the shuffle() in Deck class, you can replace it with collections if you want. Part of the assignment was to use my own random generator (based on an example in class)
    Last edited by 7nQecEL; October 30th, 2013 at 05:51 PM.

  2. #2
    Join Date
    Jul 2013
    Beans
    8

    Re: [Java] Going over code/logic for blackjack

    I think I've fixed one of the error that I was having. But I'm still getting the "java.lang.ArrayIndexOutOfBoundsException: 52" error...

  3. #3
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,294
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: [Java] Going over code/logic for blackjack

    What does RandomGenerator.generateRandomNum() do?
    「明後日の夕方には帰ってるからね。」


  4. #4
    Join Date
    Jul 2013
    Beans
    8

    Re: [Java] Going over code/logic for blackjack

    it's suppose to generate a random number to use when shuffling the deck and getting random cards. Part of the assignment was to call a method from a jar file. I made that from an example shown in class. You think that might be the problem? It's almost the exact same thing as what was shown in class

  5. #5
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,165
    Distro
    Kubuntu 14.04 Trusty Tahr

    Re: [Java] Going over code/logic for blackjack

    I'm ready to bet that the way you call it your random generator generates numbers in the range 1..52(*) while your array indices are in the range 0..51.

    (*) 52, that, not so surprisingly, appears in the error message...
    Warning: unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.

  6. #6
    Join Date
    Jul 2013
    Beans
    8

    Re: [Java] Going over code/logic for blackjack

    Gah that was it. Haha can't believe I missed that

    Thank you!

  7. #7
    Join Date
    Sep 2013
    Beans
    11

    Re: [Java] Going over code/logic for blackjack

    If you can use the Collection Class and it's shuffle() method [note 1], what is the random generator good for?

    I'm just asking because the whole task of simulating a (black jack) card deck is already perfectly solved
    in the LinkedList Class which implements the Queue interface. You just take cards from the beginning of
    the queue and put them to it's end after usage. When you arrive at the first card again you can use
    Collection.shuffle(cardDeck)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •