package XDU.Cowork.Java;
public class DriveCar {
protected static int totalVolvo = Road.startStop.numberOfVolvo + Road.endStop.numberOfVolvo;
protected static int totalIveco = Road.startStop.numberOfIveco + Road.endStop.numberOfIveco;//就是用来初始化这个所有的车的,并且做好了最坏的打算,就是所有的车全部在高速公路上跑
//创建行驶数组,但是说很有可能会存在数组的冗余
protected static Volvo[] drivingVolvo = new Volvo[totalVolvo];
protected static Iveco[] drivingIveco = new Iveco[totalIveco];
//写一个初始化的方法
protected static void initial(){
System.out.println(" " + totalVolvo + " " + totalIveco);
for(int i = 0;i < totalVolvo;i++){
if(i < Road.startStop.numberOfVolvo){
drivingVolvo[i] = Road.startStop.volvoTeam[i];
}else{
drivingVolvo[i] = Road.endStop.volvoTeam[i - Road.startStop.numberOfVolvo ];
}
System.out.println(drivingVolvo[i].licensePlateNumber + " " +drivingVolvo[i].infoToString());
}
for(int i = 0;i < totalIveco;i++){
if(i < Road.startStop.numberOfIveco){
drivingIveco[i] = Road.startStop.ivecoTeam[i];
}else{
drivingIveco[i] = Road.endStop.ivecoTeam[i - Road.startStop.numberOfIveco ];
}
System.out.println(drivingIveco[i].licensePlateNumber+ " " +drivingIveco[i].infoToString());
}
}//我打印一下看看整的对不对
//先去遍历所有的正在路上的车,更新他们的距离并判断是不是应该下车
public static void workVolvo(){
for(int i = 0;i < totalVolvo;i++){//有一说一这里的判断条件还是存在问题的
if(drivingVolvo[i].status == "DRIVING") {
drivingVolvo[i].distanceToNextStop -= Volvo.speed;
if (drivingVolvo[i].distanceToNextStop <= 0) {//这里表示进站了
//如果到了终点站,那我就先下车,然后直接转到下一班
if (drivingVolvo[i].subOfLastStop == 1 && drivingVolvo[i].direction == "NEGATIVE") {//这说明是反方向进站了,就是从宝鸡进西安了
//先更新数据,然后把他排到车队的尾端
drivingVolvo[i].direction = "POSITIVE";
drivingVolvo[i].subOfLastStop = 0;
drivingVolvo[i].distanceToNextStop = Road.road[1].numberLocation;
drivingVolvo[i].nextStopCodeName = Road.road[1].stopCodeName;
drivingVolvo[i].nextStopName = Road.road[1].name;
drivingVolvo[i].existingPassengers = 0;
drivingVolvo[i].status = "WAITING";
drivingVolvo[i].nowStopLocation = 0;
drivingVolvo[i].nowStopCodeName = Road.road[0].stopCodeName;
drivingVolvo[i].nowStopName = Road.road[0].name;
//让他排在队伍后面
Road.startStop.totalPassedVolvo++;
Road.startStop.volvoTeam[Road.startStop.totalPassedVolvo % Road.startStop.numberOfVolvo] = drivingVolvo[i];
//那这个车辆就不存在了
//我需要把他进行销毁,但是说这样还是存在一些问题的
//不需要像原先那样,只要有一个sub就可以
//continue;
}
if (drivingVolvo[i].subOfLastStop == Road.numberOfStop - 2 && drivingVolvo[i].direction == "POSITIVE") {//这说明是正方向进站了,就是从西安进宝鸡了了
//先更新数据,然后把他排到车队的尾端
drivingVolvo[i].direction = "NEGATIVE";
drivingVolvo[i].subOfLastStop = Road.numberOfStop - 1;
drivingVolvo[i].distanceToNextStop = Road.road[Road.numberOfStop - 1].numberLocation - Road.road[Road.numberOfStop - 2].numberLocation;
drivingVolvo[i].nextStopCodeName = Road.road[Road.numberOfStop - 2].stopCodeName;
drivingVolvo[i].nextStopName = Road.road[Road.numberOfStop - 2].name;
drivingVolvo[i].existingPassengers = 0;
drivingVolvo[i].status = "WAITING";
drivingVolvo[i].nowStopLocation = Road.numberOfStop - 1;
drivingVolvo[i].nowStopCodeName = Road.road[Road.numberOfStop - 1].stopCodeName;
drivingVolvo[i].nowStopName = Road.road[Road.numberOfStop - 1].name;
//让他排在队伍后面
Road.endStop.totalPassedVolvo++;
Road.endStop.volvoTeam[Road.endStop.totalPassedVolvo % Road.endStop.numberOfVolvo] = drivingVolvo[i];
//那这个车辆就不存在了
//我需要把他进行销毁,但是说这样还是存在一些问题的
//不需要像原先那样,只要有一个sub就可以
//continue;
}
//那接下来就是普普通通的进站方式啦
if (drivingVolvo[i].direction == "POSITIVE" ) {//这个地方还有条件的,就是要有人下车啊
drivingVolvo[i].subOfLastStop++;
drivingVolvo[i].nowStopName = Road.road[drivingVolvo[i].subOfLastStop].name;
drivingVolvo[i].nowStopCodeName = Road.road[drivingVolvo[i].subOfLastStop].stopCodeName;
drivingVolvo[i].nowStopLocation = Road.road[drivingVolvo[i].subOfLastStop].numberLocation;
drivingVolvo[i].nextStopName = Road.road[drivingVolvo[i].subOfLastStop + 1].name;
drivingVolvo[i].nextStopCodeName = Road.road[drivingVolvo[i].subOfLastStop + 1].stopCodeName;
drivingVolvo[i].distanceToNextStop = Road.road[drivingVolvo[i].subOfLastStop + 1].numberLocation - Road.road[drivingVolvo[i].subOfLastStop].numberLocation;
//其实写的很多都是对象的实例域,更改是必须的,但是这样写出来就像是非常冗余,我不知道有什么方法可以让他自己装填上这些,这些信息是站点的信息,但赋予的应该是类的对象
if( drivingVolvo[i].getOffPassengersOfEachStop[drivingVolvo[i].orderOfGetOffSub] != 0){
drivingVolvo[i].status = "INSTOP";
}
} else if (drivingVolvo[i].direction == "NEGATIVE" ) {//这个地方还有条件的,就是要有人下车啊
drivingVolvo[i].subOfLastStop--;
drivingVolvo[i].nowStopName = Road.road[drivingVolvo[i].subOfLastStop].name;
drivingVolvo[i].nowStopCodeName = Road.road[drivingVolvo[i].subOfLastStop].stopCodeName;
drivingVolvo[i].nowStopLocation = Road.road[drivingVolvo[i].subOfLastStop].numberLocation;
drivingVolvo[i].nextStopName = Road.road[drivingVolvo[i].subOfLastStop - 1].name;
drivingVolvo[i].nextStopCodeName = Road.road[drivingVolvo[i].subOfLastStop - 1].stopCodeName;
drivingVolvo[i].distanceToNextStop = Road.road[drivingVolvo[i].subOfLastStop].numberLocation - Road.road[drivingVolvo[i].subOfLastStop - 1].numberLocation;
//其实写的很多都是对象的实例域,更改是必须的,但是这样写出来就像是非常冗余,我不知道有什么方法可以让他自己装填上这些,这些信息是站点的信息,但赋予的应该是类的对象
if(
- 1
- 2
- 3
前往页