class racing_info{
ArrayList<horse_info> list = new ArrayList<horse_info>();
void racing_information() {
System.out.println("====경주 정보====");
for(int i=0; i<8; i++) {
int speedA = (int)(Math.random()*40)+30;
int skillA = (int)(Math.random()*50)+20;
int betA = (int)(Math.random()*9)+5;
horse_info HI = new horse_info(speedA, skillA, betA);
list.add(HI);
System.out.println((i+1) +"번마 || 마속:" + HI.returnSpeed() + " 기수의 노련함:" + HI.returnSkill() + " 배당률:" + HI.returnBet());
}System.out.println();
}
void winner_information() {
double winner = 0.0;
double max = 0.0;
System.out.println("====승자====");
for(int i=0; i<list.size(); i++) {
horse_info temp = list.get(i);
winner = (temp.returnSpeed() * 0.3) + (temp.returnSkill() * 0.2);
max = Integer.MIN_VALUE;
}
if(winner > max) {
max = winner;
System.out.println();
}
}
}
class horse_info{
int speed = 0;
int skill = 0;
int bet = 0;
horse_info(int a, int b, int c){
speed = a;
skill = b;
bet = c;
}
int returnSpeed() {return speed;}
int returnSkill() {return skill;}
int returnBet() {return bet;}
}
我做了一个简单的'赛马'代码。所以我试图通过使用'if(胜利者&gt;最大值){......'代码获得胜利的马。结果,我得到了具有最高点(='双赢者'部分)的马,但我无法得到它是哪匹马 简单地说,我想得到像这样的结果
System.out.println("No." + (i+1) + " horse is the winner!!!");
答案 0 :(得分:0)
要获得胜利者,您可以将winner
更改为代表获胜者指数的int:
void winner_information() {
int winner=0;
for(int i=0; i<list.size(); i++) {
horse_info temp = list.get(i);
if(calculateProficiency(temp) > calculateProficiency(list.get(winner))
winner = i
}
//Print your winner horse (i) info
}
double calculateProficiency(horse_info h) {
return (h.returnSpeed() * 0.3) + (h.returnSkill() * 0.2);
}
此代码,如果有多匹马具有相同的“熟练度”(并且他们是获胜者),将仅打印其中的第一匹。作为练习,你应该寻求如何展示它们。