Hashmaps在java出售飞机票 我正在为一个卖机票的应用程序做大学项目。 在提供可用的飞机座位部分,我使用哈希图制作它们,输入乘客姓名,并将行和座位作为键。 我不知道如何使用扫描仪让客户写下他想要的行和座位,并将座位标记为已占用。我要创建一个名为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); }

Hashmaps在java出售飞机票 我正在为一个卖机票的应用程序做大学项目。 在提供可用的飞机座位部分,我使用哈希图制作它们,输入乘客姓名,并将行和座位作为键。 我不知道如何使用扫描仪让客户写下他想要的行和座位,并将座位标记为已占用。我要创建一个名为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); },java,hashmap,ticket-system,Java,Hashmap,Ticket System,目前,这段代码所做的是将您的座椅对象用作键,并将名称存储为值。您应该将座位(如它的行和座位号)存储为键,并将其作为一个值,您可以设置标志,以指示该座位是否已被占用。 因此,无论何时创建座位,您都会使用该键(座位号、行、名称)在hashmap中设置true,无论何时新客户机请求相同的键,您都可以看到座位是否已被占用 代码 Integer row = Scanner.getInt("Enter your row: "); String seat = Scanner.getString("Enter

目前,这段代码所做的是将您的座椅对象用作键,并将名称存储为值。您应该将座位(如它的行和座位号)存储为键,并将其作为一个值,您可以设置标志,以指示该座位是否已被占用。 因此,无论何时创建座位,您都会使用该键(座位号、行、名称)在hashmap中设置true,无论何时新客户机请求相同的键,您都可以看到座位是否已被占用

代码

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: ");
然后使用这些字段创建您的
座位

Seta myseat = new Seat (row, seat);
Seta myseat = new Seat (row, seat);