【发布时间】:2014-03-16 18:37:51
【问题描述】:
我不确定我是否正确地执行了 for 循环以在 if 语句中给出一个真实的值。 如果我需要使用这种 for 循环,我如何增加 1。这是我正在研究的部分。
要进行预订,应提示用户输入他们希望旅行的目的地和星期几。如果存在这样的航班并且航班上有可用座位,则应输入乘客详细信息并创建新乘客。为该航班预订的座位数应加 1。
public void flightBooking(){
Passenger passenger;
String flightDay, flightDestination;
boolean found = false;
Flight myFlight = null;
Scanner scan = new Scanner(System.in);
System.out.println(" On which day do you wish to travel ? ");
flightDay = scan.nextLine();
System.out.println(" What is your destination ? ");
flightDestination = scan.nextLine();
for ( Flight d : flightList )
{
if (d.getDay().equals(flightDay))
{
myFlight= d;
found = true;
}
}
for ( Flight s : flightList )
{
if (s.getDestination().equals(flightDestination))
{
myFlight= s;
found = true;
}
}
if (found == true)
{
System.out.println("The Flight Day and Destination were found, the Flight will be booked.");
Passenger passengers = new Passenger ("Laura", "14 Rathmines Rd ","laura99@gmail.com" , myFlight);
passengerList.add(passengers);
}
else
{
System.out.println("There is no flight booking.");
}
}
【问题讨论】:
标签: java