스토리지 클래스를 생성하여 내 arraylist/Linked list의 데이터 유형으로 사용했습니다.linkedlist/arraylist to java에 객체 추가
private LinkedList bid_history;
내가
bid_history=new LinkedList <Bid_History>();
나의 constructure이를 초기화 한 나는 내용을 확인 'n'을 반복 한 후
bid_history.add(new Bid_History(bid_count,unit_price,bid_success));
아래 그림과 같이 추가 사용하여 목록에 새 항목을 추가 목록에 'n'개 요소가 있지만 모두 동일하다는 사실을 알게되었습니다. 즉, 추가 된 마지막 요소 i가 전체 목록을 차지했습니다. 마치 목록에 참조 변수를 추가 한 것입니까?
내가 실수했을 수도있는 아이디어가 있습니까? 나는 또한 같은 문제 인 arraylist를 사용했다. 액세스 지정자에 문제가 있다고 생각합니다! 하지만 난
가 ---- ------- 내가
int count=0,size;
size=bid_history.size();
while(count<size)
System.out.println(((Bid_History)bid_history.get(count++)).getBid_amount());
다음과 같이
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();
}
}
인쇄 코드는 재귀 함수를 사용하여 추가 ..... 아이디어 중입니다
표시된 코드에 문제가없는 것 같습니다. 귀하의 (편집 된) 루프 코드를 보여주십시오. 우리는 당신을 도울 더 많은 정보가 필요합니다. 또한, 그들이 모두 똑같은지 어떻게 알 수 있습니까? 그 코드도 보여주세요 – Bohemian
연속적인 반복에서'bid_count, unit_price, bid_success'의 값을 변경하고 있습니까? –
'bid_success'가 다른 함수에 의해 수정되었습니다. – Gan