Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.