Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How to specify acesor functions of objects within a vector?!!! Posted by silvakle on 26 Dec 2010 at 9:14 PM
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<Object> givenDeck) {
for (Iterator<Object> 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...



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.