Quote (shinigamiapple777 @ 31 Jan 2013 23:45)
I think I need help reorganizing the code atm now heh.
i have a class for card - has getter and setter for rank and suit
inside dealer class (is way to much that needs to be put somewhere) - initializing the deck, shuffling deck, using setter & getter for card picked, then handing 2 cards to player & 2 cards to dealer.
although I haven't put anything in yet to hand 2 cards to player or dealer, and I would rather do one card at a time in case cards need to be added to the hand.
class for player, which nothing is there atm, but i need a way to hold the 'hand' information..
empty main BlackJack class that has the public static void main(String[] args) in it.
would really like some advice on how to clean it up, etc.....please be gentle - novice here.
Okay. Here's my input in regards to distributing roles, and the classes I'd make:
- A Card class, which handles the way cards are initialized separately.
- A Deck class, containing the cards currently in the game.
- A Player class. This class has some data structure holding the cards in the player's hand, and will also be able to either hit or stay.
- A Dealer class. This class will be dealing cards to players from a Deck, exhausting the cards as he goes. I see no reason to use a polymorphic approach here, which I'd consider poor Java architecture compared to a compositional design anyways.
- A Game class. This is your skeleton class, passing turns, checking who won, setting up new rounds, all by calling appropriate methods in the respective classes.
The main idea with classes, is to delegate responsibility and roles. You need to have specific information about both individual cards, as well as an entire deck, but the two are different roles held by different actors; two classes make sure you are able to work on both things separately. The dealer should not have the responsibility to initialize the deck; he should merely deal it.
I don't know what the focus of your course and assignment is, though, so the answers may differ a little depending on that.