How to specify acesor functions of objects within a vector?!!! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to specify acesor functions of objects within a vector?!!!

silvaklesilvakle Posts: 1Member
Hi everyone!!

I'm enhancing my deck of cards application (in a nutshell, I use a vector to represent the deck, and each card is a string like "8 of Spades").

The enhancement is to make each card an actual object with several String fields ("rank", "suit", "trump", etc) and accesor functions like say getRank().

Problem is how to display the contents of my deck (the fields inside the card objects), before this did the trick

public void printDeck(Vector givenDeck) {
for (Iterator i = givenDeck.iterator(); i.hasNext();) {
System.out.println(" " + (String)i.next());
}

However, since now I would need 'instanceOfCardObject.getRank()' to see the rank field for example, how can I specify (if possible at all) the accesor function of my instace of the Card object inside the Vector while looping through it?

Can it be done at all, either by iterators or using any of the vector methods (get, elementAt, etc)? I can't seem to figure out how...
Sign In or Register to comment.