Results 21 to 35 of 35
- 03-20-2012, 12:58 AM #21
Re: Help setting values to cards in an array
Try debugging your code by adding println() statements to show execution progress and how variable values are changing. For example:
Add a: System.out.println("var=" + var);
after every line where a variable is changed by an assignment statement or read into.
Print out the value returned by getFace() and the values looked at in faces
I dont see how getCardValue() can return zero. It always adds one to value on line 10If you don't understand my response, don't ignore it, ask a question.
- 03-20-2012, 01:33 AM #22
Member
- Join Date
- Mar 2012
- Posts
- 28
- Rep Power
- 0
Re: Help setting values to cards in an array
I'm still stuck at this point... I think I'm putting the wrong argument into the getHandValue() method. I'm not sure what to put in there..
- 03-20-2012, 01:36 AM #23
Re: Help setting values to cards in an array
A method named getHandValue() should probably get a hand for an argument.
Where and how is a hand defined? Is there a Hand class? What values would a Hand object contain?If you don't understand my response, don't ignore it, ask a question.
- 03-20-2012, 01:37 AM #24
Member
- Join Date
- Mar 2012
- Posts
- 28
- Rep Power
- 0
Re: Help setting values to cards in an array
I put print statements in the getCardValue() method and nothing printed.
- 03-20-2012, 01:38 AM #25
Re: Help setting values to cards in an array
Is the method called from anywhere in the code?
If it is not called, then none of its code would execute.If you don't understand my response, don't ignore it, ask a question.
- 03-20-2012, 01:38 AM #26
Member
- Join Date
- Mar 2012
- Posts
- 28
- Rep Power
- 0
Re: Help setting values to cards in an array
This is my main args:
Java Code:public static void main( String args[] ) { DeckOfCards myDeckOfCards = new DeckOfCards(); myDeckOfCards.shuffle(); // place Cards in random order Card[] hand = new Card[ 2 ]; // store two cards // get first two cards for ( int i = 0; i < 2; i++ ) { hand[ i ] = myDeckOfCards.dealCard(); // get next card System.out.println( hand[ i ] ); } // end for myDeckOfCards.getHandValue(hand);
- 03-20-2012, 01:41 AM #27
Re: Help setting values to cards in an array
That looks like getHandValue shoud be called. Does the code compile without errors? It shouldn't execute if there are compiler errors.
If you don't understand my response, don't ignore it, ask a question.
- 03-20-2012, 01:42 AM #28
Member
- Join Date
- Mar 2012
- Posts
- 28
- Rep Power
- 0
Re: Help setting values to cards in an array
Where would I call the getCardValue() method? Inside the getHandValue() method? Where inside would I put it?
- 03-20-2012, 01:43 AM #29
Member
- Join Date
- Mar 2012
- Posts
- 28
- Rep Power
- 0
- 03-20-2012, 01:44 AM #30
Re: Help setting values to cards in an array
If you held a hand of cards, how would you manually sum up their values?
If you don't understand my response, don't ignore it, ask a question.
- 03-20-2012, 02:07 AM #31
Member
- Join Date
- Mar 2012
- Posts
- 28
- Rep Power
- 0
Re: Help setting values to cards in an array
- 03-20-2012, 02:10 AM #32
Re: Help setting values to cards in an array
You call the getCardValue() method when you want the value of a card.
I have no idea why you'd do that.what was the point in creating a card object in getHandValue()?If you don't understand my response, don't ignore it, ask a question.
- 03-20-2012, 02:23 AM #33
Member
- Join Date
- Mar 2012
- Posts
- 28
- Rep Power
- 0
Re: Help setting values to cards in an array
Okay, so I tried calling the getCardValue() method on line 24, there isn't any errors, but now the total is always coming out as 12. Why?! :( I can't see anything wrong with the code. Can you see what I'm doing wrong and point it out?
Java Code:public int getCardValue(Card card) { int val; val = 0; for (int i = 0; i > faces.length; i++) { if (faces[i].equals(card.getFace())) { val = i; break; } } value = val + 1; //adds 1 since the array starts at 0 return value; } public void getHandValue(Card hand[]) { int HandTotal; boolean ace; HandTotal = 0; ace = false; for (int i = 0; i < hand.length; i++) { int cardValue; cardValue = getCardValue(hand[i]); if (cardValue > 10) { cardValue = 10; //sets Jack, Queen and King to 10 } if (cardValue == 1) { ace = true; } HandTotal = HandTotal + cardValue; } if (ace == true && HandTotal + 10 <= 21) { HandTotal = HandTotal + 10; } System.out.printf("Hand total: %d\n", HandTotal); }
- 03-20-2012, 02:24 AM #34
Re: Help setting values to cards in an array
Try debugging your code by adding println() statements to show execution progress and how variable values are changing. For example:
Add a: System.out.println("var=" + var);
after every line where a variable is changed by an assignment statement or read into.
I'm done for today.If you don't understand my response, don't ignore it, ask a question.
- 03-20-2012, 02:28 AM #35
Member
- Join Date
- Mar 2012
- Posts
- 28
- Rep Power
- 0
Similar Threads
-
Issue with setting values in an array
By pyat77 in forum New To JavaReplies: 4Last Post: 11-04-2011, 02:01 AM -
need to input values from a text file into an array and count values
By pds8475 in forum New To JavaReplies: 14Last Post: 01-22-2011, 02:36 PM -
Setting up a String Array
By AJArmstron@aol.com in forum New To JavaReplies: 12Last Post: 04-16-2010, 12:42 PM -
setting and getting array
By jgonzalez14 in forum New To JavaReplies: 6Last Post: 11-26-2008, 06:54 AM -
setting format for FLoat values
By bugger in forum New To JavaReplies: 2Last Post: 11-16-2007, 01:22 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks