在使用Soal.Out.PrtLnf()之后,我的Java程序终止;
我在代码中的一些地方放置了system.out.println,以确定它在哪里终止,并且它似乎在执行println之后立即终止。
package exercises;
import java.util.Scanner;
public class TrainSeatBookingApplication {
public static void main(String[] args) {
// TODO Auto-generated method stub
SeatType theSeatType;
FloorGrid floorType;
TrainWay aTrainWay = null;
TrainSmart aTrainSmart = null;
Seat customerSeat;
char planeSizeChoice;
char seatingArea;
char seatEconomyOrFirst;
char programBookingChoice;
Scanner scan = new Scanner(System.in);
System.out.println("Would you like to board a petite floor sized plane or a grande floor sized plane?");
planeSizeChoice = scan.next().charAt(0);
planeSizeChoice = Character.toUpperCase(planeSizeChoice);
if (planeSizeChoice == 'P') {
floorType = new PetiteFloorGrid();
floorType.initialiseFloorGrid();
System.out.println("Would you like to be in the middle, window or asile?");
seatingArea= scan.next().charAt(0);
seatingArea = Character.toUpperCase(seatingArea);
System.out.println("Would you like to be seated in first class or middle class?");
seatEconomyOrFirst = scan.next().charAt(0);
seatEconomyOrFirst = Character.toUpperCase(seatingArea);
System.out.println("Would you like your seat to be booked via the smart program or the way program?");
programBookingChoice = scan.next().charAt(0);
programBookingChoice = Character.toUpperCase(programBookingChoice);
if (seatEconomyOrFirst == 'F') {
if (programBookingChoice == 'S') {
customerSeat = aTrainSmart.reserveFirstClass(planeSizeChoice, SeatType.MIDDLE);
System.out.println(floorType);
}
else {
customerSeat = aTrainWay.reserveFirstClass(planeSizeChoice, SeatType.MIDDLE);
System.out.println(floorType);
}
}
}
else {
floorType = new GrandeFloorGrid();
floorType.initialiseFloorGrid();
System.out.println("Would you like to be in the middle, window or asile?");
seatingArea= scan.next().charAt(0);
seatingArea = Character.toUpperCase(seatingArea);
System.out.println("Would you like to be seated in first class or middle class?");
seatEconomyOrFirst = scan.next().charAt(0);
seatEconomyOrFirst = Character.toUpperCase(seatingArea);
System.out.println("Would you like your seat to be booked via the smart program or the way program?");
programBookingChoice = scan.next().charAt(0);
programBookingChoice = Character.toUpperCase(programBookingChoice);
System.out.println("Did not reach start of if");//testing program LINE57
if (seatEconomyOrFirst == 'F') {
if (programBookingChoice == 'S') {
customerSeat = aTrainSmart.reserveFirstClass(planeSizeChoice, SeatType.MIDDLE);
System.out.println(floorType);
}
else {
customerSeat = aTrainWay.reserveFirstClass(planeSizeChoice, SeatType.MIDDLE);
System.out.println(floorType);
}
//System.out.println("Did not go through either if or else");//testing program
}
}
}
}
我还有另外两行可以做完全相同的工作(但是保存到不同的变量中),它们工作得非常好。