我正在为一个销售机票的应用程序的大学做一个项目。 在提供可用飞机座位的部分,我使用散列图制作它们,将乘客姓名以及行和座位作为键。 我不知道如何使用扫描仪要求客户写下他想要的行和座位,并将座位标记为已占用。我应该创建一个名为 seat 的类吗?如果您有什么想法,我将不胜感激。
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;
}
}
最佳答案
目前这段代码正在做的是,它使用您的座位对象作为键并将名称存储为值。您应该存储座位,例如它的行数和座位号作为键,作为一个值,您可以设置标志来判断该座位是否有人。 因此,无论何时您创建一个座位,您都可以使用该键(座位号、行、名称)将 true 放入 hashmap 中,并且每当新客户端请求相同的键时,您都可以看到该座位是否被占用。
关于java - Hashmaps 卖飞机票 java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46802751/