我试图给TrainTimeTable
添加延迟。我已经使用Date
物体使火车到达和离开。当我第一次打印时间表时,一切都显示正确的到达和离开时间。 然而,在埃德蒙顿和之后的所有车站增加了30分钟的延迟。 部分抵达和离开时间不正确。 延迟只能将抵达和离开时间推回,但它会改变一些城市之间的行程时间。日期类别问题:日期对象正在设置为我没有设置的东西
我已经作出了getter和setter方法,像这样:
/**
* Accessor for arrival Date variable. Returns a copy of the arrival date.
* @return - a copy of the arrival date
*/
public Date getArrivalDate()
{
//return a copy of the original date
return (Date) arrival.clone();
}
/**
* Mutator for arrival date variable.
* @param arrival - the date to set
*/
public void setArrivalDate(Date arrival)
{
//uses copy of Date passed in
this.arrival = (Date) arrival.clone();
}
这里是我将延迟 我用Station
的LinkedList
一个对象来保存计划方法:
public void delay(String Station, int minute) {
//sequential search for Station
//iterate through list for Station
boolean delayPoint = false;
//1) adjust time of day
//add delay to arrival and departure date objects
for (Station current : schedule) {
//By checking for delay before checking for the delay city
//we will see the delayPoint variable set while on
//the loop is at the station right afer the delayed Station
//if after the delay point
if (delayPoint) {
//then add delay to arrive date
Date arrivalDate = current.getArrivalDate();
long arrivalTime = current.getArrivalDate().getTime();
arrivalTime += minute * MIN_TO_MS;
arrivalDate.setTime(arrivalTime);
current.setArrivalDate(arrivalDate);
//and add delay to depart date
Date departDate = current.getDepartureDate();
long departTime = current.getDepartureDate().getTime();
departTime += minute * MIN_TO_MS;
departDate.setTime(departTime);
current.setDepartureDate(departDate);
} //if the Station matches the point of delay
else if (current.getCity().equals(Station)) {
//then set the boolean
delayPoint = true;
//and add delay to departure
Date departDate = current.getDepartureDate();
long departTime = current.getDepartureDate().getTime();
departTime += minute * MIN_TO_MS;
departDate.setTime(departTime);
current.setDepartureDate(departDate);
}
}
//2) adjust day of trip
}
Here is my output after adding a delay of 30 min to Edmonton departure
请和谢谢,
Ahsen Husain。
你能告诉我们'delay()'方法的调用 – Ali
'this.arrival = new Date(arrival.getTime()); – c0der