i got a class call ClientIdBandwidth.java as shown at below
public class ClientIdBandwidth
{
private int clientID;
private int bandwidth;
public ClientIdBandwidth(int clientID , int bandwidth)
{
this.clientID = clientID;
this.bandwidth = bandwidth;
}
public int getClientID()
{
return clientID;
}
public int getBandwidth()
{
return bandwidth;
}
}
i want to call the ClientIdBandwidth constructor and and put the data to the constructor? below is the code that i have do so far :
public class connectNode
{
private List[] connection;
private int totalClients;
totalClients = clientList.size(); //get the size from another class
connection = new Vector[totalClients]; //
for(int i = 0; i<totalClients; i++)
{
connection[i] = new Vector();
}
for(int i = 0; i<totalClients; i++)
{
int ID = (int)clientList.get(i);
ClientIdBandwidth cib = new ClientIdBandwidth(ID,'0');
}
after that, i have no idea how to continued on . can anyone teach me ? thanks in advance
UPDATE
sorry that i didnt make it clear.
i am now doing a p2p simulator. i have a text file :
0;2;100; // Node 0 connect to Node 2 with 100kbps
1;5;200; // Node 1 connect to Node 5 with 200kbps
i have class that will read the txt file. and it have put the total how many node(in example above is 4 which is Node 0,2,1,5) inside a list. now i want to set like node 0 is connect to node 2 with bandwidth to a vector.
Your code will work unexpected way in most of the cases. Your constructor is expecting 2 integer parameters, but you are passing one integer and one ‘char’ type. That might be the reason you are stuck/code not working/incorrect result etc (you haven’t said the exact issue).
Or else, Your
ClientBandwithobject is getting created inside a for loop. It is created and destroyed all inside that for loop. At the end, when for loop is done, there will be no instances. So after the for loop, theClientBandwithclass will remain as it is, without EXISTING objects, so you can’t get anything using getters. In this case, you will not even notice what has happened. So you are complaining you can’t “put the data into the constructor” because the instance is getting destroyed?Apart from that,
the ‘Vector’ is slow and outdated. Use
ArrayList.If you know the exact size of the Vector, I think going for an Array is a good alternative
You are creating a Vector inside a Vector. Is that is really useful here?
Use Generics
You are using 2 for loops. But as you can see, your work can be done by 1 for loop.
Follow Java Naming standards. Your second class is starting with a simple letter
if you want all the data in the Vector to be loaded to the constructor, your system will not work. Accept a
Listtype as an argumentwhen you ask a question, tell us what you really want to do