package test;
public class Plane {
double startPos;
double startSpeed;
double advance;
public Plane(double startPos,double startSpeed,double advance)
{
this.startPos=startPos;
this.startSpeed=startSpeed;
this.advance=advance;
}
public double arrive(double destPos)
{
double time;
time = (-startSpeed+(Math.sqrt(startSpeed*startSpeed+2*advance*(destPos-startPos))))/(advance);
return time;
}
public double chase(Plane plane)
{
double distance = plane.startPos-this.startPos;
double dspeed=-(plane.startSpeed-this.startSpeed);
double dadv = -(plane.advance-this.advance);
double time=0.0;
time=(-dspeed+(Math.sqrt(dspeed*dspeed+2*dadv*(distance))))/dadv;
return time;
}
public static void main(String[] args) {
Plane p1 = new Plane(1.0,2.0,0.5);
System.out.println(p1.arrive(3.0));
System.out.println(p1.chase(new Plane(5.0,1.5,0.3)));
}
}
以上是代码测试