Java 为什么';即使数组中保存了所有值,我的find方法在这里也不能工作吗?

Java 为什么';即使数组中保存了所有值,我的find方法在这里也不能工作吗?,java,arrays,javafx,Java,Arrays,Javafx,我对编程相当陌生,我似乎无法在我让程序搜索特定关键字(虽然它保存在数组中)的区域中找到问题 下面是我添加客户详细信息的代码: private void addCustomerToSeat(String[] seatBooking, String[] customerName, String[] seatBookingAndCustomerName) { Button[] seat = new Button[(SEATING_CAPACITY + 1)]; Bu

我对编程相当陌生,我似乎无法在我让程序搜索特定关键字(虽然它保存在数组中)的区域中找到问题

下面是我添加客户详细信息的代码:


private void addCustomerToSeat(String[] seatBooking, String[] customerName, String[] seatBookingAndCustomerName) {
        Button[] seat = new Button[(SEATING_CAPACITY + 1)];

        Button selectSeat = new Button(" Click to Book Seats ");
        selectSeat.setLayoutX(320);
        selectSeat.setLayoutY(512);
        selectSeat.setOnAction(event -> {
            window.setScene(scene2);
        });

        Label header = new Label("TRAIN BOOKING SYSTEM");
        header.setLayoutX(250);
        header.setLayoutY(30);
        header.setStyle("-fx-font-size: 25px;");

        Label clientName = new Label("Enter Customer Name: ");
        clientName.setLayoutX(225);
        clientName.setLayoutY(150);
        clientName.setStyle("-fx-font-size: 16px;");
        TextField cusName = new TextField();
        cusName.setLayoutX(397);
        cusName.setLayoutY(150);



        Label destination = new Label("Choose destination: ");
        destination.setLayoutX(225);
        destination.setLayoutY(200);
        destination.setStyle("-fx-font-size:16px;");

        String [] destinations = {"Colombo to Badulla", "Badulla to Colombo"};
        ComboBox Destination = new ComboBox(FXCollections.observableArrayList(destinations));
        Destination.setLayoutX(397);
        Destination.setLayoutY(200);


        Label date = new Label("Select date:");
        date.setLayoutY(275);
        date.setLayoutX(225);
        date.setStyle("-fx-font-size:16px;");

        DatePicker datePicker = new DatePicker();
        LocalDate now = LocalDate.now();
        datePicker.setValue(now);
        datePicker.setLayoutX(397);
        datePicker.setLayoutY(275);



        AnchorPane layout1 = new AnchorPane();
        layout1.setStyle("-fx-background-color:#5a89a3; ");
        layout1.getChildren().addAll(Destination,destination,selectSeat,clientName,cusName,header,date,datePicker);


        scene1 = new Scene(layout1,800,600);
        window.setTitle("Train Booking System");
        window.setScene(scene1);
        window.show();



        Label header1 = new Label("TRAIN BOOKING SYSTEM");
        header1.setLayoutX(250);
        header1.setLayoutY(30);
        header1.setStyle("-fx-font-size: 25px;");

        Button submit = new Button("Submit");
        submit.setLayoutX(640);
        submit.setLayoutY(480);
        Button exit = new Button("Exit");
        exit.setLayoutX(710);
        exit.setLayoutY(480);
        exit.setOnAction(event -> {
            window.close();
            displayMenu(seatBooking,customerName,seatBookingAndCustomerName);
        });

        Label greenSeat = new Label("Unbooked Seat");
        greenSeat.setLayoutY(160);
        greenSeat.setLayoutX(590);
        greenSeat.setStyle("-fx-font-size:14px;");
        Button unbooked = new Button("   ");
        unbooked.setLayoutY(160);
        unbooked.setLayoutX(560);
        unbooked.setStyle("-fx-background-color:green;");

        Label redSeat = new Label("Booked Seat");
        redSeat.setLayoutX(590);
        redSeat.setLayoutY(200);
        redSeat.setStyle("-fx-font-size:14px;");
        Button booked = new Button("   ");
        booked.setLayoutX(560);
        booked.setLayoutY(200);
        booked.setStyle("-fx-background-color:red;");


        GridPane gridPane = new GridPane();
        int columnIndex = 0;
        int rowIndex = 0;
        int rowIndexes = 0;

        int[] reservedSeats = new int[1];

        String seatNumber;
        for (int i = 1; i < (SEATING_CAPACITY + 1); i++) {
            if (i <= 9) {
                seatNumber = "0" + (i);
            } else {
                seatNumber = "" + (i);
            }
            seat[i] = new Button(seatNumber);
            gridPane.add(seat[i], columnIndex, rowIndex);
            columnIndex++;
            rowIndexes++;

            if (rowIndexes == 4) {
                columnIndex = 0;
                rowIndexes = 0;
                rowIndex++;
            }
        }
        for (int f = 1; f < (SEATING_CAPACITY + 1); f++) {
            if (seatBooking[f].equals("Empty")) {
                seat[f].setStyle("-fx-background-color: green;");
            }
            if (seatBooking[f].equals("booked")) {
                seat[f].setStyle("-fx-background-color: red");
            }
        }

        List<Integer> bookedCurrent = new ArrayList<>();
        for (int f = 1; f < (SEATING_CAPACITY + 1); f++) {
            int finalF = f;
            seat[f].setOnAction(event -> {
                seat[finalF].setStyle("-fx-background-color: red");
                seatBooking[finalF] = "booked";
                bookedCurrent.add(finalF);
            });

            submit.setOnAction(event -> {
                String personName = cusName.getText();
                personName = personName.toLowerCase();
                window.close();


                for ( int loopSeatArray = 1; loopSeatArray< (SEATING_CAPACITY + 1); loopSeatArray++) {
                    if (loopSeatArray == reservedSeats[0]) {
                        seatBooking[loopSeatArray] = "Booked";
                        customerName[loopSeatArray] = personName;
                    }
                    seatBookingAndCustomerName[loopSeatArray] = seatBooking[loopSeatArray];
                }
                for (int total = 43; total < (SEATING_CAPACITY + 1); total++){
                    seatBookingAndCustomerName[total]= customerName[total-42];                }
                displayMenu(seatBooking, customerName, seatBookingAndCustomerName);
            });
        }

        gridPane.setLayoutX(160);
        gridPane.setLayoutY(80);
        gridPane.setHgap(20);
        gridPane.setVgap(5);


        AnchorPane layout2 = new AnchorPane();
        layout2.setStyle("-fx-background-color:#5a89a3; ");
        layout2.getChildren().addAll(gridPane,submit,exit,header1,greenSeat,unbooked,redSeat,booked);

        scene2 = new Scene(layout2,800,600);
        window.setTitle("Train Booking System");
        window.show();
        window.setOnCloseRequest(event -> {
            window.close();
            displayMenu(seatBooking,customerName,seatBookingAndCustomerName);
        });

    }


private void addCustomerToSeat(字符串[]座位预订,字符串[]客户名称,字符串[]座位预订和客户名称){
按钮[]座位=新按钮[(座位容量+1)];
按钮selectSeat=新建按钮(“单击预订座位”);
选择座椅。设置布局X(320);
选择座椅。设置布局(512);
选择座椅。设置操作(事件->{
窗口设置场景(场景2);
});
标签标题=新标签(“列车预订系统”);
标题.setLayoutX(250);
标题。设置布局(30);
header.setStyle(“-fx字体大小:25px;”);
Label clientName=新标签(“输入客户名称:”);
clientName.setLayoutX(225);
clientName.setLayoutY(150);
clientName.setStyle(“-fx字体大小:16px;”);
TextField cusName=新建TextField();
cusName.setLayoutX(397);
cusName.setLayoutY(150);
标签目的地=新标签(“选择目的地:”);
目的地:setLayoutX(225);
目的地:setLayoutY(200);
destination.setStyle(“-fx字体大小:16px;”);
字符串[]目的地={“科伦坡到巴杜拉”,“巴杜拉到科伦坡”};
ComboBox Destination=新的ComboBox(FXCollections.observableArrayList(destinations));
目的地:setLayoutX(397);
目的地:setLayoutY(200);
标签日期=新标签(“选择日期:”);
日期:setLayoutY(275);
日期:setLayoutX(225);
date.setStyle(“-fx字体大小:16px;”);
DatePicker DatePicker=新的日期选择器();
LocalDate now=LocalDate.now();
datePicker.setValue(现在);
datePicker.setLayoutX(397);
日期选择器。setLayoutY(275);
锚烷布局1=新锚烷();
布局1.setStyle(“-fx背景色:#5a89a3;”);
layout1.getChildren().addAll(目的地、目的地、selectSeat、clientName、cusName、标题、日期、日期选择器);
场景1=新场景(布局1800600);
window.setTitle(“火车订票系统”);
窗口设置场景(场景1);
window.show();
标签头1=新标签(“列车预订系统”);
标题1.设置布局X(250);
校长1.设置布局(30);
header1.setStyle(“-fx字体大小:25px;”);
按钮提交=新按钮(“提交”);
提交setLayoutX(640);
提交.setLayoutY(480);
按钮退出=新按钮(“退出”);
出口。setLayoutX(710);
出口。setLayoutY(480);
exit.setOnAction(事件->{
window.close();
显示菜单(座椅预定、客户名称、座椅预定和客户名称);
});
标签绿色座椅=新标签(“未预订座椅”);
绿色果肉。setLayoutY(160);
greenSeat.setLayoutX(590);
greenSeat.setStyle(“-fx字体大小:14px;”);
未预订按钮=新按钮(“”);
未煮熟的。setLayoutY(160);
未烘焙。setLayoutX(560);
未烘焙的.setStyle(“-fx背景色:绿色;”);
标签红色座椅=新标签(“预订座椅”);
redSeat.setLayoutX(590);
红色座椅。设置布局(200);
redSeat.setStyle(“-fx字体大小:14px;”);
按钮预订=新按钮(“”);
预定。setLayoutX(560);
预定。setLayoutY(200);
.setStyle(“-fx背景色:红色;”);
GridPane GridPane=新建GridPane();
int columnIndex=0;
int rowIndex=0;
int-rowIndexes=0;
int[]reservedSeats=新int[1];
字符串座位号;
对于(int i=1;i<(座位容量+1);i++){
如果(i){
座位[finalF].setStyle(“-fx背景色:红色”);
座椅预定[finalF]=“预订”;
bookedCurrent.add(最终);
});
submit.setOnAction(事件->{
字符串personName=cusName.getText();
personName=personName.toLowerCase();
window.close();
对于(int loopSeatArray=1;loopSeatArray<(座位容量+1);loopSeatArray++){
if(loopSeatArray==reservedSeats[0]){
座位预定[loopSeatArray]=“预订”;
customerName[loopSeatArray]=人名;
}
座椅预定和客户名称[loopSeatArray]=座椅预定[loopSeatArray];
}
对于(总人数=43;总人数<(座位容量+1);总人数++){
座椅预定和客户名称[总计]=客户名称[总计-42];}
显示菜单(座椅预定、客户名称、座椅预定和客户名称);
});
}
gridPane.setLayoutX(160);
设置布局(80);
gridPane.setHgap(20);
gridPane.setVgap(5);
锚烷布局2=新锚烷();
布局2.setStyle(“-fx背景色:#5a89a3;”);
layout2.getChildren().addAll(gridPane、submit、exit、header1、greenSeat、Unboked、redSeat、booked);
场景2=新场景(布局2800600);
window.setTitle(“火车订票系统”);
window.show();
window.setOnCloseRequest(事件->{
window.close();
显示菜单(座椅预定、客户名称、座椅预定和客户名称);
});
}
下面是代码的一部分,我提示用户输入名称并查找给定名称的位置:

private void findCustomerSeats(字符串[]座位预订、字符串[]客户名称、字符串[]座位预订和客户名称){
扫描仪输入=新扫描仪(System.in);
System.out.println(“请输入客户名称:”);
字符串名称=input.nextLine();
布尔标志=假;
对于(int i=1;i<(座位_
for (int idx = 0; idx < customerName.length; idx++) {
//This way you will not check an index of your array that does not exist 
//which could cause a NullPointerException
//Additionally, this is useful if you want to grow your customerName array
}
System.out.println("Inputted Name: " + name);
for (int idx = 0; idx < customerName.length; idx++) {
System.out.println("Does " + name.toLowerCase() + " = " + customerName[idx] + " ?");
}