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 TypeMethodDescriptionvoid
Fetches the recordedRental
objects from the filerentals.txt
.static RentalDatabase
Returns the singleton instance ofRentalDatabase
.getItemById
(String id) Retrieves a rental by its ID.void
Saves the list ofRental
objects 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:
getItemById
in classDatabase<Rental>
- Parameters:
id
- the ID of the rental.- Returns:
- the
Rental
with the specified ID, ornull
if not found.
-
fetchFromDisk
public void fetchFromDisk()Fetches the recordedRental
objects from the filerentals.txt
.- Specified by:
fetchFromDisk
in classDatabase<Rental>
-
saveToDisk
public void saveToDisk()Saves the list ofRental
objects to the filerentals.txt
.- Specified by:
saveToDisk
in classDatabase<Rental>
-