I'm going through the following steps and I'm having an issue when saving the original file.
- Read file to objects
- Add objects to arraylist
- override toString method for printing to console
- save file repeat.
The issue is repeating as the file layout has now changed. I'm trying to find a method to print to the file without all of the appends.
I've looked into 2 different ways, ignore words while reading, and trying to remove the words before saving. Both of which seemed really messy and confusing.
Here is my StringBuilder:
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Room Number: ").append(roomNumber);
builder.append(", Room Type: ").append(roomType);
builder.append(", Room Price: £").append(format.format(roomPrice));
builder.append(", Room Balcony: ").append(roomBalcony);
builder.append(", Room Lounge: ").append(roomLounge);
builder.append(", Room Reserved by: ").append(reservedBy);
builder.append("\n");
return builder.toString();
}
Here is my filescanner
while (file.hasNextLine()) {
int roomNumber = file.nextInt();
String roomType = file.next();
double roomPrice = file.nextDouble();
boolean roomBalcony = file.nextBoolean();
boolean roomLounge = file.nextBoolean();
String reservedBy = file.next();
roomList.add(new Room(roomNumber, roomType, roomPrice, roomBalcony, roomLounge, reservedBy));
}