Package bcu.cmp5332.bookingsystem.data
Class BookingDataManager
java.lang.Object
bcu.cmp5332.bookingsystem.data.BookingDataManager
- All Implemented Interfaces:
DataManager
The BookingDataManager class implements the DataManager interface
to manage loading and storing of booking data to/from a text file.
It provides methods to load existing bookings data into a FlightBookingSystem instance,
and to store current bookings data from a FlightBookingSystem instance into a text file.
The booking data is stored in a text file specified by the RESOURCE constant. Each line in the file represents a booking record, separated by the SEPARATOR "::".
The loadData method reads from the text file, parses each line to retrieve booking details, and adds the parsed bookings to the provided FlightBookingSystem instance.
The storeData method retrieves all bookings from the provided FlightBookingSystem instance, formats them into a string representation, and writes them to the text file for storage.
Example usage:
// Create a new instance of FlightBookingSystem and BookingDataManager
FlightBookingSystem fbs = new FlightBookingSystem();
BookingDataManager bookingDataManager = new BookingDataManager();
// Load existing booking data into FlightBookingSystem
bookingDataManager.loadData(fbs);
// Perform operations on fbs...
// Store current booking data from FlightBookingSystem
bookingDataManager.storeData(fbs);
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Loads existing booking data from the bookings data file into the provided FlightBookingSystem instance.void
Stores current booking data from the provided FlightBookingSystem instance into the bookings data file.
-
Field Details
-
RESOURCE
The path to the bookings data file.- See Also:
-
-
Constructor Details
-
BookingDataManager
public BookingDataManager()
-
-
Method Details
-
loadData
Loads existing booking data from the bookings data file into the provided FlightBookingSystem instance. Each line in the file represents a booking record with fields separated by the SEPARATOR.- Specified by:
loadData
in interfaceDataManager
- Parameters:
fbs
- The FlightBookingSystem instance to load booking data into- Throws:
IOException
- If there is an error reading the data fileFlightBookingSystemException
- If there is an error parsing the booking data
-
storeData
Stores current booking data from the provided FlightBookingSystem instance into the bookings data file. Each booking's details are formatted and written to the file, separated by the SEPARATOR.- Specified by:
storeData
in interfaceDataManager
- Parameters:
fbs
- The FlightBookingSystem instance to store booking data from- Throws:
IOException
- If there is an error writing data to the file
-