Article View: aus.computers.java
Article #1113Enumerators and Vectors...
From: Steve Hewitt
Date: Sat, 24 Jul 1999 00:00
Date: Sat, 24 Jul 1999 00:00
38 lines
2017 bytes
2017 bytes
Can anyone please help with the following...
I have been asked to write a class called 'ItemSet' which holds a number of
Item objects (already defined).
The Items are stored within a vector and typical methods are 'addItem()',
'removeItem()', 'getItems()' etc, etc.
I have been told to use the Enumerator class but I am having a few problems.
What exactly do I need to include within the ItemSet class to make use of
the Enumerator class? I understand that it is used to iterate through
elements of an object and that I must declare two methods - public boolean
hasMoreElements() and public Object nextElement() - but how does it all fit
together?
As an example I have a method which should return all Items that are
contained within the set. I have coded this to be :
// returns a String of relevant set details
public String toString()
{
String setDetails = new String();
for (Enumeration e = items.elements() ; e.hasMoreElements() ;)
setDetails = setDetails + e.nextElement() + '\n';
return setDetails;
}
where 'items' is the Vector containing all of the Items in the set. What should the methods hasMoreElements and nextElement contain? and is the implementation of the method above correct?
Any help would be much appreciated.
Steve
steve@bert44.freeserve.co.uk
hewitts@abs-ltd.com
Technical Details
Message-ID:
<7ncojq$bf6$1@news8.svr.pol.co.uk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d6db,e1c8263d0c15df19,start X-Google-Attributes: gid10d6db,public From: "Steve Hewitt" <Steve@bert44.freeserve.co.uk> Subject: Enumerators and Vectors... Date: 1999/07/24 Message-ID: <7ncojq$bf6$1@news8.svr.pol.co.uk> X-Deja-AN: 504772532 X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 X-Complaints-To: abuse@theplanet.net X-Trace: news8.svr.pol.co.uk 932832698 11750 62.136.186.89 (24 Jul 1999 16:11:38 GMT) Organization: Customer of Planet Online X-MSMail-Priority: Normal NNTP-Posting-Date: 24 Jul 1999 16:11:38 GMT Newsgroups: aus.computers.java