我正在尝试创建一个名为 isAvailable 的布尔方法,它接受航班上的座位号作为参数,返回一个指示该座位是否可用的布尔值。使用类似于井字游戏程序的代码,该代码会将座位号(如 20)转换为二维数组的行和列索引。如果航班上有任何可用座位,则返回 true。
public class Flight {
/*
* declare instance variables
* each flight object that is created will have its own copy of these
* These are declared as private to ensure that external Java code
* cannot access them directly and assign any arbitrary values to them.
*/
String flightNumber;
int rows;
int seatsPerRow;
boolean [][] seat;
double fare;
String origin;
String destination;
/*
* The constructor
* Contains code that initially sets up each flight object when it is
* first created. Always has the same name as the class.
*/
public Flight (String flightNumber, int rows, int seatsPerRow, double fare, String origin, String destination) {
//call the mutator methods and let them initialize the instance variables
setflightNumber(flightNumber);
setRows(rows);
setSeatsPerRow(seatsPerRow);
setFare(fare);
setOrigin(origin);
setDestination(destination);
seat = new boolean [rows][seatsPerRow]
for(int i = rows, int x = seatsPerRow; i>0, x>0; i--, x--){
seat[i][x] = true;
}
}//end of constructor
/*
* The accessor methods
* These report the current values of the Flight object's instance variables
*/
public String getFlightNumber() {
return flightNumber;
}
public int getRows() {
return rows;
}
public int getSeatsPerRow() {
return seatPerRow;
}
public double getFare() {
return fare;
}
public String getOrigin() {
return origin;
}
public String getDestination() {
return destination;
}
public boolean isAvailable(int userRow, int userSeatPerRow) {
int row = 0;
int seatPerRow = 0;
}
}//end of accessors