我正在为一个卖机票的大学做一个项目。在提供飞机座位的部分,我用散列图制作,把乘客的名字和排座位作为关键。我不知道如何使用扫描仪要求客户写下他想要的排和座位,并标记为已被占用的座位。我应该创建一个名为“座位”的班级吗?如果你有什么想法,我会非常感激的。
public AsientosConNombre(Integer row, String seat) {
super(row, seat);
}
public static void main(String[] args) {
String nombrePasajero = Scanner.getString("Enter your name: ");
Seat1 asientopasajero= new Seat1(AsientosConNombre);
//creo el hashmap
HashMap<Seat1, String> Asientos = new HashMap<Seat1, String>();
//llenamos el hashmap con la informacion ingresada por el pasajero.
Asientos.put(asientopasajero, nombrePasajero );
//esto deberia devolver la app clientes cuando el usuario indica su nombre para saber su vuelo.
// (ademas del horario y fecha del vuelo)
System.out.println("Your information: "+ Asientos);
}我做的另一门课是:
public class Seat1 {
Integer row = Scanner.getInt("Enter your row: ");
String seat = Scanner.getString("Enter your seat: ");
public Seat1(Integer row, String seat) {
this.row = row;
this.seat = seat;
}
public boolean full(boolean occupied){
return occupied;
}
}发布于 2017-10-18 04:28:24
目前,这段代码所做的是使用您的name对象作为键,并将名称作为值存储。您应该将座椅(如它的行号和座位号)存储为键,并作为一个值设置标志,以判断该座位是否已被占用。因此,每当您创建一个座位时,您都会在哈希映射中使用该键(座位号、行、名),每当一个新客户端请求相同的键时,您就可以看到该座位是否已被占用。
发布于 2017-10-18 05:02:44
密码
Integer row = Scanner.getInt("Enter your row: ");
String seat = Scanner.getString("Enter your seat: ");需要在代码块中,它不能仅仅停留在您定义字段的位置。
尝试进入您的main方法
Integer row = Scanner.getInt("Enter your row: ");
String seat = Scanner.getString("Enter your seat: ");然后使用这些字段创建您的Seat
Seta myseat = new Seat (row, seat);https://stackoverflow.com/questions/46802751
复制相似问题