Class CustomerDataManager

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

public class CustomerDataManager extends Object implements DataManager
The CustomerDataManager class implements the DataManager interface to manage loading and storing of customer data to/from a text file. It provides methods to load existing customer data into a FlightBookingSystem instance, and to store current customer data from a FlightBookingSystem instance into a text file.

The customer data is stored in a text file specified by the RESOURCE constant. Each line in the file represents a customer record, separated by the SEPARATOR "::".

The loadData method reads from the text file, parses each line to retrieve customer details, and adds the parsed customers to the provided FlightBookingSystem instance.

The storeData method retrieves all customers 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 CustomerDataManager
 FlightBookingSystem fbs = new FlightBookingSystem();
 CustomerDataManager customerDataManager = new CustomerDataManager();
 
 // Load existing customer data into FlightBookingSystem
 customerDataManager.loadData(fbs);
 
 // Perform operations on fbs...
 
 // Store current customer data from FlightBookingSystem
 customerDataManager.storeData(fbs);
 
See Also:
  • Constructor Details

    • CustomerDataManager

      public CustomerDataManager()
  • Method Details

    • loadData

      public void loadData(FlightBookingSystem fbs) throws IOException, FlightBookingSystemException
      Loads existing customer data from the customers data file into the provided FlightBookingSystem instance. Each line in the file represents a customer record with fields separated by the SEPARATOR.
      Specified by:
      loadData in interface DataManager
      Parameters:
      fbs - The FlightBookingSystem instance to load customer data into
      Throws:
      IOException - If there is an error reading the data file
      FlightBookingSystemException - If there is an error parsing the customer data
    • storeData

      public void storeData(FlightBookingSystem fbs) throws IOException
      Stores current customer data from the provided FlightBookingSystem instance into the customers data file. Each customer'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 customer data from
      Throws:
      IOException - If there is an error writing data to the file