I created a storage class and use to as the data type for my arraylist/Linked list.
private LinkedList bid_history;
I have initialised this in my constructure as
bid_history=new LinkedList <Bid_History> ();
I add new items to the list using add as illustrated below
bid_history.add(new Bid_History(bid_count,unit_price,bid_success));
After 'n' iterations I checked the contents of the list and found out that the list has 'n' elements but they were the same. i.e. the last element i added occupied the entire list. It is as if i added a reference variable to the list?
Any idea where I might have made a mistake? I also used an arraylist, the same problem. I am guessing I did something wrong with access specifiers! but I am out of ideas.....
----Added ------- I use a recursive function
bid()
{
int bid,quantity;
bid_success=false;
bid_count++;
System.out.println("Starting to bid, Bid ID:"+bid_count);
quantity=(int)(rated_power*duration/60);
if(bid_history.isEmpty())
{
unit_price=10;
}
else
{
unit_price++;
}
bid=unit_price*quantity;
//Sending the calculated bid
send_res(unit_price,quantity,500);
long startTimeMs = System.currentTimeMillis( );
System.out.println("Time:"+startTimeMs);
while(!(System.currentTimeMillis( )>(startTimeMs+2000)));
System.out.println("Time at end:"+System.currentTimeMillis( ));
bid_history.add(new Bid_History(bid_count,unit_price,bid_success));
if(bid_success!=true)
{
bid();
}
}
the printing code is as follows
int count=0,size;
size=bid_history.size();
while(count<size)
System.out.println(((Bid_History)bid_history.get(count++)).getBid_amount());
bid_count, unit_price, bid_successin the successive iterations?bid_successis modified by another function.