Jeremy Graham wrote:I can't seem to figure out how to make unique objects for an arraylist using a for loop... Any ideas how?
Thanks
Dennis Deems wrote:
So: you already know how to instantiate an object in a method and add it to a list. Doing it inside a loop isn't any different.
And making Suit and Rank into enums makes it much easier to find one of those “various ways”.Jeff Verdegan wrote: . . . special handling for J, Q, K, A, but there are various ways to deal with that.
Campbell Ritchie wrote:I still think the earlier suggestion about enums was good. If you are up to reading the Java Language Specification and about the Enum class, that will provide more useful information.
This is a great idea.Jeff Verdegan wrote:I think it makes sense to do it without enums first, to learn how it can be done with looping and arrays, and then to do it again with enums, as a compare-and-contrast exercise.
Jeremy Graham wrote:but it counts 2 cards as non Spades (as oppoesed to 4).
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
No, it doesn’t. That’s why I said, “If you are up to reading . . .”Dennis Deems wrote:. . . But I don't think the JLS makes beginner-friendly reading. . . .
Jeremy Graham wrote:
What is stumping me right now is Jeff's suggestion that I use java.util.Random.nextInt() instead of Math.random(). In trying to use it I'm getting the error: "non-static method nextInt(int) cannot be referenced from a static context".
Jeremy Graham wrote:Here's my Card object:
...
Junilu Lacar wrote:EDIT: Now I feel a little icky... seems I just kicked a Zombie, too
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Don't get me started about those stupid light bulbs. |