在下面,您将看到我的代码摘要。我需要对getTopBids进行排序,以使最高出价排在第一,其次是第二高,以此类推。...我该怎么做? Java的新手-这是我在学校的第一个作业!
public String getTopBids(){
StringBuilder topBids = new StringBuilder();
ArrayList<String> topBidsName = new ArrayList<>();
ArrayList<Integer> topBidsAmount = new ArrayList<>();
for(int i = 0; i < 3; i++) {
String name = "";
int amount = 0;
for (Bid bid : this.getBidding()) {
if(amount < bid.getAmount() && !topBidsAmount.contains(bid.getAmount())) {
name = bid.getUser().getName();
amount = bid.getAmount();
}
}
if(amount != 0){
topBidsName.add(name);
topBidsAmount.add(amount);
}
}
for (int i = 0; i < topBidsName.size(); i++){
topBids.append(String.format("%s %d kr", topBidsName.get(i),
topBidsAmount.get(i)));
if(i != topBidsName.size()) topBids.append(", ");
}
return topBids.toString(); }
}