我的目标是创建Dragster和Dragrace类。我的dragster类已经完成,但是我对如何完成我的DragRace类一无所知。主要方法应该显示这样的结果。


  减速器特性:反应时间:0.6,扭矩:1000,牵引力:0.8286078156824775,燃烧时间:3
  
  Dragster时间:6.663417763058126秒。


我必须创建一个包含5个Dragster的数组,然后显示每个数组的结果。

public class Dragster {
    private int burnTime;
    private double reactionTime;
    private int torque;
    private double traction;

    public Dragster(double reactionTime, int torque, double traction, int     burnTime) {
    this.reactionTime = reactionTime;
    this.torque = torque;
    this.traction = traction;
    this.burnTime = burnTime;

}

private double conditionTires(double time){
    double effectiveness = 2.5*(Math.exp((time * time - (10 * time) + 25) / 50))/Math.sqrt(2 * Math.PI);
    return effectiveness;

}

public void burnout(){
    traction = traction * conditionTires(burnTime);
}

public double race(){
    double TORQUE2TIME = 5000;
    double raceTime = reactionTime + (1/(torque/ TORQUE2TIME)*conditionTires(burnTime));
    return raceTime;
}

public String toString(){
    return "Reaction Time:" + reactionTime + ", Torque:" + torque + "Traction:" + traction +
            "Burn Time:" + burnTime;

}
}


public class DragRace {

    private DragRace{

    }
    public static void main(String[] args){
        ArrayList<Dragster> DragsterList = new ArrayList<Dragster>();
        Dragster car1 = new Dragster(0.6, 1000, 0.9, 3);
        Dragster car2 = new Dragster(0.4, 800, 1.0, 5);
        Dragster car3 = new Dragster(0.5, 1200, 0.95, 7);
        Dragster car4 = new Dragster(0.3, 1200, 0.95, 1);
        Dragster car5 = new Dragster(0.4, 900, 0.9, 6);
        DragsterList.add(car1);
        DragsterList.add(car2);
        DragsterList.add(car3);
        DragsterList.add(car4);
        DragsterList.add(car5);
        DragsterList.toString();



    }
}


我在dragrace课上迷失了下一步的工作。如果有人可以提供一些见识。

最佳答案

只需执行以下操作:

public void printResults() {
    for (Dragster d: DragsterList) {
        System.out.println(d.toString());
        System.out.println();
        System.out.println("Dragster time:" + d.race());
    }
}


基本上,您只需要遍历列表中的每辆汽车,打印汽车并进行一次赛车。

10-07 13:41