When I try "deck.add("Ace","Spades",11);" i get a compile error of "cannot find symbol - method add(java.lang.String,java.lang.String.int)"
Does anyone have a clue or tip that can point me in the right direction? I've tried googling but a lot of crap is for just arrays or the arraylists only pass in one parameter.
Thanks.
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
posted
0
Rene Rad wrote:
When I use " deck.add(new Card("Ace","Hearts",11));" it puts in info but not properly. When I print the output it comes out with...
This is happening because the Card class doesn't have a proper toString() method. You need to fix that by either giving it a toString method or rather than trying to print the array at once, iterate through it with a for loop and print each Card's fields one at at time.
When I try "deck.add("Ace","Spades",11);" i get a compile error of "cannot find symbol - method add(java.lang.String,java.lang.String.int)"
look carefully at how you're handling this add and you'll see it's quite different (and incorrect) from the others.
Rene Rad
Greenhorn
Joined: Feb 10, 2010
Posts: 15
posted
0
pete stein wrote:
Rene Rad wrote:
When I use " deck.add(new Card("Ace","Hearts",11));" it puts in info but not properly. When I print the output it comes out with...
This is happening because the Card class doesn't have a proper toString() method. You need to fix that by either giving it a toString method or rather than trying to print the array at once, iterate through it with a for loop and print each Card's fields one at at time.
When I try "deck.add("Ace","Spades",11);" i get a compile error of "cannot find symbol - method add(java.lang.String,java.lang.String.int)"
look carefully at how you're handling this add and you'll see it's quite different (and incorrect) from the others.
I know the second one is different, just something else I was trying. So are you saying that "deck.add(new Card("Ace","Hearts",11));" is in fact putting the correct information into the ArrayList? Cuz when I inspect it I get this... (see attached image)
Rene Rad
Greenhorn
Joined: Feb 10, 2010
Posts: 15
posted
0
Nevermind, my Card Class had a logic error in the constructor. The suit parameter wasn't being passed into the instance variable.
Thanks for your help .
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
posted
0
Rene Rad wrote:
I know the second one is different, just something else I was trying. So are you saying that "deck.add(new Card("Ace","Hearts",11));" is in fact putting the correct information into the ArrayList?
I believe so, since deck is an ArrayList of Card type, you must add a Card objects. Your showDeck() method looks wrong:
The line:
is printing out the whole ArrayList, deck with each iteration. Rather than do that it should print out the i'th item, and ArrayList has a method that should be called here to allow you to do this.