This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes adding objects to a vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "adding objects to a vector " Watch "adding objects to a vector " New topic

adding objects to a vector

Kelly Frasure

Joined: Mar 03, 2001
Posts: 15
I have created 2 classes. Customer and CustomerList. I would like to add customers to the customer list. How can I make new objects in the vector using information from my Customer class.
This is the code I have so far.
public Customer (String client, String number, double funds)
name = client;
phone = number;
balance = funds;
// Returns a description of this Customer.
public String toString()
NumberFormat fmt = NumberFormat.getCurrencyInstance();
String description;
description = name + "\t" + phone + "\t" + fmt.format(balance);
return description;
import java.util.Vector;
import Customer;
public class CustomerList
// Stores the list of savings account customers.
public static void main (String[] args)
Vector Customer = new Vector();
Customer.addElement ();
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

(I don't have any java books with me at the moment, but I will give it a try.)
First you don't want to say "Vector Customer = new Vector();" because this will only confuse you. Say something like
Vector CustList = new Vector() ;
So you have a vector called "CustList" into which you are going to place Customer objects.
Than something like this:
Customer Cust1 = new Customer( <parms> ) ;
CustList.addElement( Cust1) ;
So you make a Customer, than add them to the vector. Hope that helps.

Please ignore post, I have no idea what I am talking about.
I agree. Here's the link:
subject: adding objects to a vector
It's not a secret anymore!