Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: Adding to a Vector problem
|
Posted: Jun 5, 2002 10:40 PM
|
|
I think this is what you are trying to do. I've changed the method parameter names to try and help clarify the difference between the parameters for the constructor and those for the other method.
Incidentally, it seems like this method would be a static one. However, it might be a better idea to have a Customer class and a separate CustomerCollection class, which can contain a collection of Customer objects. Having a Customer object contain a list of Customer objects seems a little confusing (like, does the object contain itself in the list? Do all Customer objects contain all other Customer objects in their lists?).
import java.util.Vector;
public class Customer
{
private Vector bankCustomers = new Vector();
String first_name,
last_name;
long phone_number;
public Customer( String firstName, String lastName, long phoneNumber )
{
first_name = firstName;
last_name = lastName;
phone_number = phoneNumber;
}
public void addNewCustomer(String Fname, String Lname, long phoneN )
{
// Adds the new Customer to the BankCustomer Vector.
bankCustomers.addElement( new Customer( Fname,Lname,phoneN ) );
}
}
|
|