• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

adding objects to a vector

 
Kelly Frasure
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic