-
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());
}
}
-
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?
-
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.
-
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.
-
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
-
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.
-
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
-
Re: Java BlackJack game