Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes creating names for vectors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "creating names for vectors" Watch "creating names for vectors" New topic
Author

creating names for vectors

Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
I want to make an unlimited number of vectors and need to call then something to keep track of them is there a way to do this. I have code that I want to avoid

if(POI > 2 )
{
Vector POI3 = new Vector();
System.out.println("Enter POI one number at a time DO NOT enter the comma's ");
for(int i = 1; i <= len; i++)
{
String input = br.readLine();
int p = Integer.parseInt(input);
POI3.addElement(new Integer(p));
}
Enumeration EnPOI3 = POI3.elements();
while(EnPOI3.hasMoreElements())
System.out.print(EnPOI3.nextElement() +", ");
System.out.println();
System.out.println("Enter coordinates");
String POI3co = br.readLine();
}
if(POI > 3 )
{
Vector POI4 = new Vector();
System.out.println("Enter POI one number at a time DO NOT enter the comma's ");
for(int i = 1; i <= len; i++)
{
String input = br.readLine();
int p = Integer.parseInt(input);
POI4.addElement(new Integer(p));
}
Enumeration EnPOI4 = POI4.elements();
while(EnPOI4.hasMoreElements())
System.out.print(EnPOI4.nextElement() +", ");
System.out.println();
System.out.println("Enter coordinates");
String POI4co = br.readLine();
}
Vector v1 = new Vector();
System.out.println("Enter vector one number at a time DO NOT enter the comma's ");
for(int i = 0; i < len; i++)
{
String input = br.readLine();
int p = Integer.parseInt(input);
v1.addElement(new Integer(p));

}
if(number > 1 )
{
Vector v2 = new Vector();
System.out.println("Enter vector one number at a time DO NOT enter the comma's ");
for(int i = 1; i <= len; i++)
{
String input = br.readLine();
int p = Integer.parseInt(input);
v2.addElement(new Integer(p));
}
}
if(number > 2 )
{
Vector v3 = new Vector();
System.out.println("Enter vector one number at a time DO NOT enter the comma's ");
for(int i = 1; i <= len; i++)
{
String input = br.readLine();
int p = Integer.parseInt(input);
v3.addElement(new Integer(p));
}
}
if(number > 3 )
{
Vector v4 = new Vector();
System.out.println("Enter vector one number at a time DO NOT enter the comma's ");
for(int i = 1; i <= len; i++)
{
String input = br.readLine();
int p = Integer.parseInt(input);
v4.addElement(new Integer(p));

}
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
What about an array of Vectors?
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
can you have that. I never tried. Thanks
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Yes, you can create an array of object references.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Given that you want an unlimited number, why not a Vector of Vectors, or an ArrayList of ArrayLists?


There is no emoticon for what I am feeling!
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
Thank you everyone I got it working.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: creating names for vectors