This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "adding objects to a vector " Watch "adding objects to a vector " New topic
Author

adding objects to a vector

Kelly Frasure
Greenhorn

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: 984

(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.
 
jQuery in Action, 2nd edition
 
subject: adding objects to a vector
 
Similar Threads
Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
Null Point Exception
toString method in vector.
StrutsPrepareandExecutefilter error
Problem With Method and Interface