我想做 "if a person book a seat the available seats must be depreciate by one"。我怎样才能做到这一点?
i want to do "if a person book a seat the available seats must be depreciate by one". how can i do that?
过程是“我预订了一个座位,可用座位必须减少一个座位。可用座位数为 35。我想我必须为此使用数组,但我不知道使用方法
下面的代码 (available_seats) 就是我要显示可用座位的地方。
try {
String route_number = rnB.toString();
String depature_on = doB.toString();
String depature_time = dtB.toString();
String time_taken = timeB.toString();
String available_seats = asB.toString();
String price = pB.toString();
String custname = name.toString();
String custcontact = contact.toString();
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/eurobusdb?useSSL=false","root","Abc123");
String SQL_INSERT_BOOKING = "INSERT INTO booking (Depature_Country_And_City , Destination_Country_And_City, Depature_On, Depature_Time, Estimated_Time_Taken, Available_Seats, Price, Status, route, name, contact_number) VALUES ( ?,?,?,?,?,?,?,?,?,?,?);";
PreparedStatement preparedStatement = connection.prepareStatement(SQL_INSERT_BOOKING);
System.out.println(preparedStatement);
preparedStatement.setString(1, String.valueOf(combo1.getSelectedItem()));
preparedStatement.setString(2, String.valueOf(combo2.getSelectedItem()));
preparedStatement.setString(3, doB.getText());
preparedStatement.setString(4, dtB.getText());
preparedStatement.setString(5, timeB.getText());
preparedStatement.setString(6, asb.getText());
preparedStatement.setString(7, pB.getText());
preparedStatement.setString(8, "Booked");
preparedStatement.setString(9, rnB.getText());
preparedStatement.setString(10, name.getText());
preparedStatement.setString(11, contact.getText());
preparedStatement.executeUpdate();
System.out.println(preparedStatement);
}
} catch (Exception e) {
}
根据您发布的内容,我觉得您需要将座位数的值硬编码为 n
即
int n = 35;
从那时起,创建一个方法来预订座位,当从前端调用该方法时,将值减一。
return_type bookSeat(someParameters...){
// Some Function Code
n--;
}
如果您想要特定的信息,例如座位号以及该座位是否已预订,请输入
然后创建一个类似于
的布尔数组
boolean arr[n+1] // denoting one based indexing
并且最初将标志值设置为 true 或 false 以表示是否已预订,然后在预订座位时检查座位是否已预订。
如果假设我需要检查第 23 个座位是否已预订
我们可以检查
if(seatArr[23] == true){
//Some function or output
}
else{
//Something else
}
过程是“我预订了一个座位,可用座位必须减少一个座位。可用座位数为 35。我想我必须为此使用数组,但我不知道使用方法
下面的代码 (available_seats) 就是我要显示可用座位的地方。
try {
String route_number = rnB.toString();
String depature_on = doB.toString();
String depature_time = dtB.toString();
String time_taken = timeB.toString();
String available_seats = asB.toString();
String price = pB.toString();
String custname = name.toString();
String custcontact = contact.toString();
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/eurobusdb?useSSL=false","root","Abc123");
String SQL_INSERT_BOOKING = "INSERT INTO booking (Depature_Country_And_City , Destination_Country_And_City, Depature_On, Depature_Time, Estimated_Time_Taken, Available_Seats, Price, Status, route, name, contact_number) VALUES ( ?,?,?,?,?,?,?,?,?,?,?);";
PreparedStatement preparedStatement = connection.prepareStatement(SQL_INSERT_BOOKING);
System.out.println(preparedStatement);
preparedStatement.setString(1, String.valueOf(combo1.getSelectedItem()));
preparedStatement.setString(2, String.valueOf(combo2.getSelectedItem()));
preparedStatement.setString(3, doB.getText());
preparedStatement.setString(4, dtB.getText());
preparedStatement.setString(5, timeB.getText());
preparedStatement.setString(6, asb.getText());
preparedStatement.setString(7, pB.getText());
preparedStatement.setString(8, "Booked");
preparedStatement.setString(9, rnB.getText());
preparedStatement.setString(10, name.getText());
preparedStatement.setString(11, contact.getText());
preparedStatement.executeUpdate();
System.out.println(preparedStatement);
}
} catch (Exception e) {
}
根据您发布的内容,我觉得您需要将座位数的值硬编码为 n 即
int n = 35;
从那时起,创建一个方法来预订座位,当从前端调用该方法时,将值减一。
return_type bookSeat(someParameters...){
// Some Function Code
n--;
}
如果您想要特定的信息,例如座位号以及该座位是否已预订,请输入 然后创建一个类似于
的布尔数组boolean arr[n+1] // denoting one based indexing
并且最初将标志值设置为 true 或 false 以表示是否已预订,然后在预订座位时检查座位是否已预订。 如果假设我需要检查第 23 个座位是否已预订 我们可以检查
if(seatArr[23] == true){
//Some function or output
}
else{
//Something else
}