私はオブジェクトを定義してから、ファイルマネージャから多数のオブジェクトを作成しました。私はwhileループを使ってこれらのオブジェクトをArrayListに追加したままにしておき、後で使用するためにそれらを保存します。Java - arraylistからオブジェクトを印刷する
私は現在、オブジェクトを文字列として出力しようとしています。さまざまな属性(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();
int、double、およびbooleanを持つオブジェクトの問題はどうなりますか? –