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 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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: adding objects to a vector
 
Similar Threads
Problem With Method and Interface
toString method in vector.
Null Point Exception
StrutsPrepareandExecutefilter error
Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]