I'm creating a program that deals cards at random. It has three classes in it: Card, DeckOfCards, Test(not shown here).
My issue is with using "rank" and "suit" in the DeckOfCards class sine they were initiated and defined in the card class.
Basically, you've defined "suit" and "rank" as instance variables of the Card class. That means you need to have an instance of Card in order to use "suit" and "rank." For example, if you create an instance...
Card myCard = new Card();
...then you can access the suit array as myCard.suit, or get its length using myCard.suit.length.
Note that the variable "myCard" (or whatever you call it) needs to be within the scope you're using it -- for example, somewhere in the Deck.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
You would probably want to declare rank and suit static i.e make these arrays belong to the class since they aren't defining attributes of any instance of the class Card.
You can access public static variables without an instance of the class like this:
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?