我已经定义了一个对象,然后从文件扫描器创建了大量对象。我已经通过一个while循环将这些对象添加到ArrayList中以存储它们以备后用。Java - 从阵列列表中打印对象
我现在试图打印出所说的对象作为字符串,我发现的问题是它有各种属性(int,string,double,boolean,boolean,boolean)。
下面是对象:
class Room {
int roomNumber;
String roomType;
double roomPrice;
boolean roomBalcony;
boolean roomLounge;
boolean roomReserved;
public Room(int roomNumber, String roomType, double roomPrice, boolean roomBalcony, boolean roomLounge, boolean roomReserved) {
this.roomNumber = roomNumber;
this.roomType = roomType;
this.roomPrice = roomPrice;
this.roomBalcony = roomBalcony;
this.roomLounge = roomLounge;
this.roomReserved = roomReserved;
}
这是扫描仪。
while(file.hasNextLine()){
int roomNumber = file.nextInt();
String roomType = file.next();
double roomPrice = file.nextDouble();
boolean roomBalcony = file.nextBoolean();
boolean roomLounge = file.nextBoolean();
boolean roomReserved = false;
rooms.add(new Room(roomNumber, roomType, roomPrice, roomBalcony, roomLounge, roomReserved));
file.nextLine();}
file.close();
具有整数,双精度和布尔值的对象的问题究竟是什么? –