我正在做一个大学的销售机票的应用程序项目。
在提供飞机座位的过程中,我将使用哈希图,将乘客姓名以及行和座位作为关键。
我不知道如何使用扫描仪要求客户写下他想要的行和座位,并将座位标记为已占用。我可以创建一个名为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;
    }
}

最佳答案

当前,此代码正在执行的操作是将您的Seat对象用作键并将名称存储为值。您应该将座位(例如行号和座位号)存储为键,并可以设置一个标志来标识该座位是否已被占用。
因此,无论何时创建席位,都将使用该键(席位号,行,名称)将其放入哈希图中,并且每当新客户端请求相同的键时,您都可以查看席位是否被占用。

10-05 20:33