2017-10-18 37 views
3

我正在做一个销售机票的应用程序的大学项目。 在提供飞机座位的部分,我正在做他们与hashmaps,把乘客的名字,和行&座位为关键。 我不知道如何使用扫描仪要求客户写下他想要的排和座位,并将座位标记为已占用。我应该创建一个名为座位的班级吗?如果你有一些想法,我会非常感激。HashMap售飞机票java

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; 
    } 
} 

回答

0

目前这是什么代码正在做的是,它是使用你的座位对象作为重点,并存储名称作为值。你应该存放座位,例如它的排和座位号码作为钥匙,并且作为一个值,你可以设置标志,告诉座位是否被占用。 因此,无论何时您要创建一个座位,您都必须将该关键字(座位号,行,名称)置于散列表中,并且每当新客户端请求相同的密钥时,您就可以看到该座位是否被占用。

0

代码

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);