Package bcu.cmp5332.bookingsystem.data
Class CustomerDataManager
java.lang.Object
bcu.cmp5332.bookingsystem.data.CustomerDataManager
- All Implemented Interfaces:
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:
-
Field Summary
Fields inherited from interface bcu.cmp5332.bookingsystem.data.DataManager
SEPARATOR
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Loads existing customer data from the customers data file into the provided FlightBookingSystem instance.void
Stores current customer data from the provided FlightBookingSystem instance into the customers data file.
-
Constructor Details
-
CustomerDataManager
public CustomerDataManager()
-
-
Method Details
-
loadData
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 interfaceDataManager
- Parameters:
fbs
- The FlightBookingSystem instance to load customer data into- Throws:
IOException
- If there is an error reading the data fileFlightBookingSystemException
- If there is an error parsing the customer data
-
storeData
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 interfaceDataManager
- Parameters:
fbs
- The FlightBookingSystem instance to store customer data from- Throws:
IOException
- If there is an error writing data to the file
-