I got some education in Java and everything you see in this program is something I was introduced to.
There is a linked list with 4 of each card from 1 to 10. Can someone show how I could add all hte face cards (valued at 10) and maybe even give me step by step instructions on how to exchange the 1 for an 11 and have the 11 turn into 1 when the hand goes over 21. If anyone could provide help I would very much appreciate it.
That's a lot of code to expect someone to go through, especially with such vague questions. I'll give it a shot, though...
Your lines 31-40 seem to count from 1 to 10, and then for each value, add it four times to the deck. So that would give you 40 cards. You now need to add 12 more cards, all valued at 10, right?
I'd just do another loop, and add them in.
If you want my HONEST opinion, i'd throw this out and start over. I'd make a 'card' class that hold (among possible other things) a rank, a suit, and perhaps a value.
I'd build a deck class that contains cards. I'd design the constructor to initialize the deck in a sorted order, and provide it a shuffle() method.
I'd design a 'hand' class that holds cards. It can return how many cards are in the hand, and also return the value of the hand. So it would compute the value. it would basically add up all the values, assuming each ace was worth "11". If the hand was over 21, and I had one or more aces, I'd then subtract 10 and see if the value was now 21 or under, looping for each ace in the hand...
Note - just typing that out implies I may need to keep track of how many aces are in the hand as well...
Never ascribe to malice that which can be adequately explained by stupidity.
Joined: Oct 13, 2005
fred rosenberger wrote:. . . keep track of how many aces are in the hand as well...