Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Java BlackJack game

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Java BlackJack game

    Hi i have started creating a game (blackjack) using java language, but i don't seem to be getting the "hand" class testing working, if there's anyone that could assist me id appreciate it much thanks.

    this is the hand class and the test class for the game:

    import java.util.ArrayList;


    public class Hand {
    private ArrayList<Card> playerhand;

    public Hand( ) {
    playerhand = new ArrayList<Card>();

    }

    public void addCard(Card c) {
    playerhand.add(c);
    }

    public void removeCard(int i){
    playerhand.remove(i);
    }


    //Method to return the current score of hand,
    //loop through all the cards in the hand and add their value up
    //then return it as an int
    public int getHandTotal(){
    int total = 0;

    for (Card card : playerhand){


    total = total + card.getValue();

    }

    return total;


    }

    }

    //TEST

    import java.util.ArrayList;


    public class testHand {

    /**
    * @param args
    */

    public static void main(String[] args) {
    Deck d;
    Card c;
    Hand h;
    //int cardsInHand = 0;

    d = new Deck();
    h = new Hand();
    c = new Card();

    d.shuffleTheDeck();


    h.addCard(c);


    System.out.println("Hand contains:" + c);


    System.out.println("Value of hand is " + h.getHandTotal());

    }
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java BlackJack game

    When posting code, please use the highlight tags to preserve formatting. Also, you should post an SSCCE that we can run to see the problem.

    What exactly do you mean when you say that you can't get it working?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    kas123 (April 19th, 2012)

  4. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java BlackJack game

    thanks for the advice kevin.

    well basically i have created 5 classes in total, "card", "player", "deck", "hand" and "gameEngine" now i want to create tests for these classes, i am having trouble making a test for the classes and need some help.

  5. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java BlackJack game

    What do you want to test, exactly? I know you want to test to make sure things "work", but think about exactly what that means for each piece. How do you test to make sure each piece does what you expect? You'll probably have to add more functions that let you test specific pieces and functions at a time.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java BlackJack game

    well i want to test if the actual game works, so by doing a test class for the gameEngine, in other words making the game do wat it should (play blackJack) as then i can continue on and make my gui

  7. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java BlackJack game

    ...so you're asking how to implement your game? What have you tried? Where are you stuck? It seems to me like that's the entire point of the assignment, so we can't just do it for you.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #7
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java BlackJack game

    well so far i am trying to get the hand test sorted, (as i have posted earlier) what i am trying to do is for it to add 2 cards from the deck into the hand, and then display the value of it, so far it is not doing nothing it just runs and displays no card being added, this is what i need help with.

    thanks

  9. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java BlackJack game

    Like I said, we can't really help without an SSCCE.

    Recommended reading: http://www.javaprogrammingforums.com...e-posting.html
    And: http://www.javaprogrammingforums.com...t-println.html
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Blackjack game
    By roscowgo in forum Java Theory & Questions
    Replies: 5
    Last Post: January 17th, 2012, 12:21 PM
  2. BlackJack Java
    By programming_nerd in forum Member Introductions
    Replies: 0
    Last Post: November 19th, 2011, 07:14 AM
  3. How to add card images to Blackjack game??
    By Jayc44 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 15th, 2011, 12:43 PM
  4. BlackJack Game can"t figure out how to finsh it.
    By flurr in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 13th, 2011, 10:06 AM
  5. Help with blackjack game
    By santosd1118 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 12th, 2010, 12:55 AM

Tags for this Thread