Desperately need help with some java programming

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Why are you declaring new blackJack objects in your drawCard and compareUsed methods?
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Originally posted by: tiggersbowl1
So I can pass arguements.

Is there a better way to do this?

Yes, you can pass the arguments to the current object by using this.

For example,

this.compareUsed(car, sui);
 

tiggersbowl1

Senior member
Aug 20, 2003
789
0
0
Here is my latest code, need to try to get the int's twoOfDiamonds, etc. to remember their value I assigned, so they can't be drawn again.

Thanks.
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
You need to initialize the values for your twoOfDiamonds, threeOfDiamonds, etc. variables.

You could use a two-dimensional array to keep track of what cards have been drawn. It would be a lot cleaner than what you currently have.

You also need to mark sure that you catch the condition when all cards have been drawn. Otherwise, drawCard will enter an infinite loop.
 

boran

Golden Member
Jun 17, 2001
1,526
0
76
okay dont get me wrong but you're not doing any OO at all, you could just as wel program that game in assembler.

you need to define an object card, that has a suit and a value, and a function toString (or something like it) that gives the card value as a string, next you need to define a class shoe which contains 52 cards (in a collection, I think a LinkedList is the best in terms of performance but that's kind of besides the point here) then you can shuffle your shoe (Collections.shuffle method) and then you can just simply draw cards, this is where linkedList comes into play, you can removeFromFront which actually removes the card out of the deck list. this makes the whole deck and cards behave quite like their real life counterparts and eliminates 99% of your if/else code.

my code for a card and shoe are available at my website (directory link:
http://users.telenet.be/boran/cardShoe/ ) and will remain there untill I really need the full 2 KB it's taking ;)

please try to understand the workings instead of blindly using since that will help you much more in your entire app.

(attaching code was not allowed because of the typed LinkedList :/)


edit: as a sidenote, declare methods that are internally used (such as the compare) private.

Edit2: I despise the code windows on these forums, I cant even select all code innit and copy/paste to an editor to see what it looks like as a whole.

Edit3: okay possible in IE, you have a faulty indentation after your if (selection == JOptionPane.NO_OPTION) the following for loop should start one tab level to the left since it is not within the if block but happens after the if if the if did not execute.

 

boran

Golden Member
Jun 17, 2001
1,526
0
76
Okay no more edits, new post ;) :p I made a simple solution to what you want to achieve, it's a bit crappy code in terms of structure but does exactly what you seem to want to do in your code. I have attached it, but it wont run without the aforementioned Card and Shoe classes. I have also put it on the aforementioned site.

when compiling make sure that the packages are correct. Because I use enums my classes have to be in a package in order for the deck to know the suit and face enums. so make sure classes are in the domain package.

edit: ignore my comment about wrong indentation, the code window probably did that for you. messed up mine too.