Package crms.lib
Class RentalDatabase
The
RentalDatabase class is responsible for managing rental
operations including fetching recorded Rental objects from the local
database, checking car availability, and generating rental reports.
This class follows the singleton pattern to ensure that only one instance of
RentalDatabase is created.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoidFetches the recordedRentalobjects from the filerentals.txt.static RentalDatabaseReturns the singleton instance ofRentalDatabase.getItemById(String id) Retrieves a rental by its ID.voidSaves the list ofRentalobjects to the filerentals.txt.
-
Method Details
-
getInstance
Returns the singleton instance ofRentalDatabase. If the instance does not exist, it is created and the rentals are fetched from disk.- Returns:
- the singleton instance of
RentalDatabase.
-
getItemById
Retrieves a rental by its ID.- Specified by:
getItemByIdin classDatabase<Rental>- Parameters:
id- the ID of the rental.- Returns:
- the
Rentalwith the specified ID, ornullif not found.
-
fetchFromDisk
public void fetchFromDisk()Fetches the recordedRentalobjects from the filerentals.txt.- Specified by:
fetchFromDiskin classDatabase<Rental>
-
saveToDisk
public void saveToDisk()Saves the list ofRentalobjects to the filerentals.txt.- Specified by:
saveToDiskin classDatabase<Rental>
-