Class BookingDataManager

java.lang.Object
bcu.cmp5332.bookingsystem.data.BookingDataManager
All Implemented Interfaces:
DataManager

public class BookingDataManager extends Object implements 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 Details

  • Constructor Details

    • BookingDataManager

      public BookingDataManager()
  • Method Details

    • loadData

      public void loadData(FlightBookingSystem fbs) throws IOException, FlightBookingSystemException
      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 interface DataManager
      Parameters:
      fbs - The FlightBookingSystem instance to load booking data into
      Throws:
      IOException - If there is an error reading the data file
      FlightBookingSystemException - If there is an error parsing the booking data
    • storeData

      public void storeData(FlightBookingSystem fbs) throws IOException
      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 interface DataManager
      Parameters:
      fbs - The FlightBookingSystem instance to store booking data from
      Throws:
      IOException - If there is an error writing data to the file