我得到「的飛行提供匹配信息」 「記錄乘客的詳細信息和預訂完成」從for循環中的if退出for循環?
但後來我也越來越「有沒有航班飛往該目的地」
for (int k = 0;k <=4; k++)
{
if (destination.equalsIgnoreCase(flights[k].getDestination()))
{
k = 5;
System.out.print("\nEnter desired day of departure: ");
day = scan.nextLine();
System.out.println("\f");
if (day.equalsIgnoreCase(flights[k].getDay()))
{
if (flights[k].getBookedSeats() < 100)
{
passengers[0 + bookedSeats].setName(name);
passengers[0 + bookedSeats].setAddress(address);
passengers[0 + bookedSeats].setEmail(email);
passengers[0 + bookedSeats].setOnFlight(k);
flights[k].increaseBookedSeats();
System.out.println("\nA flight is available matching this information");
System.out.println("Passenger's details recorded and booking completed");
}else{
System.out.println("\nThere are no seats available on this flight");
}
}else
{
System.out.println("\nThere are no flights flying to this destination on this day");
}
}else if(!destination.equalsIgnoreCase(flights[k].getDestination()) && k==4)
{
System.out.println("\nThere are no flights flying to this destination");
}
}
這是什麼問題? – Kick
你應該向我們展示'flight [k] .getBookedSeats()'做了什麼? – ItachiUchiha
上帝原諒我,但你也可以用標籤打破;-) http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/ java/nutsandbolts/examples/BreakWithLabelDemo.java(ok,not really) – Leo