Car Rental Service Low level System design
- Manbodh ratre
- Jun 12, 2024
- 6 min read
System Overview
The car rental application allows users to search for available vehicles at specific stores, make reservations, manage bookings, and handle payments. The application supports multiple user roles such as Admin and Customer and includes both location and store management.
Modules and Classes
User Management
User: A base class for all types of users.
Attributes: userID, name, email, password, contactInfo
Methods: login(), logout(), updateProfile()
Customer: Inherits from User.
Attributes: driver's license, rentalHistory
Methods: searchVehicle(), bookVehicle(), cancelBooking(), makePayment()
Admin: Inherits from User.
Attributes: adminID
Methods: addVehicle(), removeVehicle(), updateVehicleDetails(), addStore(), removeStore(), updateStoreDetails(), addLocation(), removeLocation(), updateLocationDetails(), viewReports()
Location Management
Location: Represents a rental location.
Attributes: locationID, name, address, contactInfo
Methods: updateAddress(), updateContactInfo()
LocationManager: Manages the collection of locations.
Attributes: list of locations
Methods: addLocation(), removeLocation(), findLocationById(), findLocationsByName(), updateLocationDetails()
Store Management
Store: Represents a rental store within a location.
Attributes: storeID, name, locationID, contactInfo
Methods: updateContactInfo()
StoreManager: Manages the collection of stores.
Attributes: list of stores
Methods: addStore(), removeStore(), findStoreById(), findStoresByLocation(), updateStoreDetails()
Vehicle Management
Vehicle: Represents a vehicle available for rent.
Attributes: vehicleID, make, model, year, storeID, rentalPrice, status (available, booked, maintenance), type (car, bike)
Methods: updateStatus(), updateStore(), updateType()
VehicleInventory: Manages the collection of vehicles.
Attributes: list of vehicles
Methods: addVehicle(), removeVehicle(), findVehicleById(), findAvailableVehicles(), findVehiclesByStore(), updateVehicleDetails()
Booking Management
Booking: Represents a booking made by a customer.
Attributes: bookingID, vehicleID, customerID, bookingDate, startDate, endDate, status (confirmed, cancelled)
Methods: updateStatus(), calculateTotalCost()
BookingManager: Handles booking operations.
Attributes: list of bookings
Methods: createBooking(), cancelBooking(), findBookingById(), getBookingsByCustomer()
Payment Management
Payment: Handles payment details for bookings.
Attributes: paymentID, bookingID, amount, paymentDate, paymentMethod (credit card, debit card, PayPal)
Methods: processPayment(), refundPayment()
PaymentGateway: Interface for processing payments through different gateways.
Methods: initiatePayment(), processResponse(), handleRefund()
Notifications
Notification: Manages notifications sent to users.
Attributes: notificationID, userID, message, date, status (sent, pending)
Methods: sendNotification(), updateStatus()
Database Schema
1 Users Table
Column Name | Data Type | Constraints |
userID | INT | PRIMARY KEY, AUTO_INCREMENT |
name | VARCHAR | NOT NULL |
VARCHAR | UNIQUE, NOT NULL | |
password | VARCHAR | NOT NULL |
contactInfo | VARCHAR | |
userType | ENUM | ('Customer', 'Admin') |
2 Locations Table
Column Name | Data Type | Constraints |
locationID | INT | PRIMARY KEY, AUTO_INCREMENT |
name | VARCHAR | NOT NULL |
address | VARCHAR | |
contactInfo | VARCHAR |
3 Stores Table
Column Name | Data Type | Constraints |
storeID | INT | PRIMARY KEY, AUTO_INCREMENT |
name | VARCHAR | NOT NULL |
locationID | INT | FOREIGN KEY (locations) |
address | VARCHAR | |
contactInfo | VARCHAR |
4 Vehicles Table
Column Name | Data Type | Constraints |
vehicleID | INT | PRIMARY KEY, AUTO_INCREMENT |
make | VARCHAR | NOT NULL |
model | VARCHAR | NOT NULL |
year | INT | |
storeID | INT | FOREIGN KEY (stores) |
rentalPrice | DECIMAL | |
status | ENUM | ('available', 'booked', 'maintenance') |
type | ENUM | ('car', 'bike') |
5 Bookings Table
Column Name | Data Type | Constraints |
bookingID | INT | PRIMARY KEY, AUTO_INCREMENT |
vehicleID | INT | FOREIGN KEY (vehicles) |
customerID | INT | FOREIGN KEY (users) |
bookingDate | DATE | |
startDate | DATE | |
endDate | DATE | |
status | ENUM | ('confirmed', 'cancelled') |
6 Payments Table
Column Name | Data Type | Constraints |
paymentID | INT | PRIMARY KEY, AUTO_INCREMENT |
bookingID | INT | FOREIGN KEY (bookings) |
amount | DECIMAL | |
paymentDate | DATE | |
paymentMethod | ENUM | ('credit card', 'debit card', 'PayPal') |
User Class
public abstract class User {
private int userID;
private String name;
private String email;
private String password;
private String contactInfo;
public User(int userID, String name, String email, String password, String contactInfo) {
this.userID = userID;
this.name = name;
this.email = email;
this.password = password;
this.contactInfo = contactInfo;
}
public void login() {
// Implement login logic
}
public void logout() {
// Implement logout logic
}
public void updateProfile(String name, String contactInfo) {
this.name = name;
this.contactInfo = contactInfo;
}
// Getters and Setters
}
Customer Class
public class Customer extends User {
private String driversLicense;
private List<Booking> rentalHistory;
public Customer(int userID, String name, String email, String password, String contactInfo, String driversLicense) {
super(userID, name, email, password, contactInfo);
this.driversLicense = driversLicense;
this.rentalHistory = new ArrayList<>();
}
public List<Vehicle> searchVehicle(Store store) {
// Implement vehicle search logic
return new ArrayList<>();
}
public void bookVehicle(Vehicle vehicle, Date startDate, Date endDate) {
// Implement vehicle booking logic
}
public void cancelBooking(int bookingID) {
// Implement booking cancellation logic
}
public void makePayment(int bookingID, double amount) {
// Implement payment logic
}
// Getters and Setters
}Admin Class
public class Admin extends User {
public Admin(int userID, String name, String email, String password, String contactInfo) {
super(userID, name, email, password, contactInfo);
}
public void addVehicle(Vehicle vehicle, Store store) {
store.addVehicle(vehicle);
}
public void removeVehicle(int vehicleID, Store store) {
store.removeVehicle(vehicleID);
}
public void updateVehicleDetails(Vehicle vehicle) {
// Implement vehicle update logic
}
public void addStore(Store store) {
// Implement store addition logic
}
public void removeStore(int storeID) {
// Implement store removal logic
}
public void updateStoreDetails(Store store) {
// Implement store update logic
}
public void addLocation(Location location) {
// Implement location addition logic
}
public void removeLocation(int locationID) {
// Implement location removal logic
}
public void updateLocationDetails(Location location) {
// Implement location update logic
}
public void viewReports() {
// Implement report viewing logic
}
}
Location Class
public class Location {
private int locationID;
private String name;
private String address;
private String contactInfo;
public Location(int locationID, String name, String address, String contactInfo) {
this.locationID = locationID;
this.name = name;
this.address = address;
this.contactInfo = contactInfo;
}
public void updateAddress(String address) {
this.address = address;
}
public void updateContactInfo(String contactInfo) {
this.contactInfo = contactInfo;
}
// Getters and Setters
}
Location Manager Class
public class LocationManager {
private List<Location> locations;
public LocationManager() {
this.locations = new ArrayList<>();
}
public void addLocation(Location location) {
locations.add(location);
}
public void removeLocation(int locationID) {
locations.removeIf(location -> location.getLocationID() == locationID);
}
public Location findLocationById(int locationID) {
return locations.stream()
.filter(location -> location.getLocationID() == locationID)
.findFirst()
.orElse(null);
}
public List<Location> findLocationsByName(String name) {
return locations.stream()
.filter(location -> location.getName().equalsIgnoreCase(name))
.collect(Collectors.toList());
}
public void updateLocationDetails(Location location) {
// Implement location update logic
}
}
Store Class
public class Store {
private int storeID;
private String name;
private int locationID;
private String address;
private String contactInfo;
private List<Vehicle> vehicles;
public Store(int storeID, String name, int locationID, String address, String contactInfo) {
this.storeID = storeID;
this.name = name;
this.locationID = locationID;
this.address = address;
this.contactInfo = contactInfo;
this.vehicles = new ArrayList<>();
}
public void updateAddress(String address) {
this.address = address;
}
public void updateContactInfo(String contactInfo) {
this.contactInfo = contactInfo;
}
public void addVehicle(Vehicle vehicle) {
vehicles.add(vehicle);
}
public void removeVehicle(int vehicleID) {
vehicles.removeIf(vehicle -> vehicle.getVehicleID() == vehicleID);
}
// Getters and Setters
}
StoreManager Class
public class StoreManager {
private List<Store> stores;
public StoreManager() {
this.stores = new ArrayList<>();
}
public void addStore(Store store) {
stores.add(store);
}
public void removeStore(int storeID) {
stores.removeIf(store -> store.getStoreID() == storeID);
}
public Store findStoreById(int storeID) {
return stores.stream()
.filter(store -> store.getStoreID() == storeID)
.findFirst()
.orElse(null);
}
public List<Store> findStoresByLocation(int locationID) {
return stores.stream()
.filter(store -> store.getLocationID() == locationID)
.collect(Collectors.toList());
}
public void updateStoreDetails(Store store) {
// Implement store update logic
}
}Vehicle Class
public class Vehicle {
private int vehicleID;
private String make;
private String model;
private int year;
private int storeID;
private double rentalPrice;
private String status;
private String type;
public Vehicle(int vehicleID, String make, String model, int year, int storeID, double rentalPrice, String status, String type) {
this.vehicleID = vehicleID;
this.make = make;
this.model = model;
this.year = year;
this.storeID = storeID;
this.rentalPrice = rentalPrice;
this.status = status;
this.type = type;
}
public void updateStatus(String status) {
this.status = status;
}
public void updateStore(int storeID) {
this.storeID = storeID;
}
public void updateType(String type) {
this.type = type;
}
// Getters and Setters
}VehicleInventory Class
public class VehicleInventory {
private List<Vehicle> vehicles;
public VehicleInventory() {
this.vehicles = new ArrayList<>();
}
public void addVehicle(Vehicle vehicle) {
vehicles.add(vehicle);
}
public void removeVehicle(int vehicleID) {
vehicles.removeIf(vehicle -> vehicle.getVehicleID() == vehicleID);
}
public Vehicle findVehicleById(int vehicleID) {
return vehicles.stream()
.filter(vehicle -> vehicle.getVehicleID() == vehicleID)
.findFirst()
.orElse(null);
}
public List<Vehicle> findAvailableVehicles() {
return vehicles.stream()
.filter(vehicle -> vehicle.getStatus().equals("available"))
.collect(Collectors.toList());
}
public List<Vehicle> findVehiclesByStore(int storeID) {
return vehicles.stream()
.filter(vehicle -> vehicle.getStoreID() == storeID)
.collect(Collectors.toList());
}
public void updateVehicleDetails(Vehicle vehicle) {
// Implement vehicle update logic
}
}Booking Class
import java.util.Date;
public class Booking {
private int bookingID;
private int vehicleID;
private int customerID;
private Date bookingDate;
private Date startDate;
private Date endDate;
private String status;
public Booking(int bookingID, int vehicleID, int customerID, Date bookingDate, Date startDate, Date endDate, String status) {
this.bookingID = bookingID;
this.vehicleID = vehicleID;
this.customerID = customerID;
this.bookingDate = bookingDate;
this.startDate = startDate;
this.endDate = endDate;
this.status = status;
}
public void updateStatus(String status) {
this.status = status;
}
public double calculateTotalCost(double rentalPricePerDay) {
long duration = endDate.getTime() - startDate.getTime();
long days = TimeUnit.MILLISECONDS.toDays(duration);
return days * rentalPricePerDay;
}
// Getters and Setters
}Booking Manager
public class BookingManager {
private List<Booking> bookings;
public BookingManager() {
this.bookings = new ArrayList<>();
}
public void createBooking(Booking booking) {
bookings.add(booking);
}
public void cancelBooking(int bookingID) {
Booking booking = findBookingById(bookingID);
if (booking != null) {
booking.updateStatus("cancelled");
}
}
public Booking findBookingById(int bookingID) {
return bookings.stream()
.filter(booking -> booking.getBookingID() == bookingID)
.findFirst()
.orElse(null);
}
public List<Booking> getBookingsByCustomer(int customerID) {
return bookings.stream()
.filter(booking -> booking.getCustomerID() == customerID)
.collect(Collectors.toList());
}
}Payment Class
import java.util.Date;
public class Payment {
private int paymentID;
private int bookingID;
private double amount;
private Date paymentDate;
private String paymentMethod;
public Payment(int paymentID, int bookingID, double amount, Date paymentDate, String paymentMethod) {
this.paymentID = paymentID;
this.bookingID = bookingID;
this.amount = amount;
this.paymentDate = paymentDate;
this.paymentMethod = paymentMethod;
}
public void processPayment() {
// Implement payment processing logic
}
public void refundPayment() {
// Implement refund logic
}
// Getters and Setters
}Payment Gateway
public interface PaymentGateway {
void initiatePayment(Payment payment);
void processResponse(String response);
void handleRefund(Payment payment);
}Notification class
import java.util.Date;
public class Notification {
private int notificationID;
private int userID;
private String message;
private Date date;
private String status;
public Notification(int notificationID, int userID, String message, Date date, String status) {
this.notificationID = notificationID;
this.userID = userID;
this.message = message;
this.date = date;
this.status = status;
}
public void sendNotification() {
// Implement notification sending logic
}
public void updateStatus(String status) {
this.status = status;
}
// Getters and Setters
}Main Class
public class Main {
public static void main(String[] args) {
// Create locations
Location location1 = new Location(1, "Downtown", "123 Main St", "123-456-7890");
Location location2 = new Location(2, "Airport", "456 Airport Rd", "987-654-3210");
LocationManager locationManager = new LocationManager();
locationManager.addLocation(location1);
locationManager.addLocation(location2);
// Create stores
Store store1 = new Store(1, "Downtown Store", location1.getLocationID(), "123 Main St", "123-456-7890");
Store store2 = new Store(2, "Airport Store", location2.getLocationID(), "456 Airport Rd", "987-654-3210");
StoreManager storeManager = new StoreManager();
storeManager.addStore(store1);
storeManager.addStore(store2);
// Create vehicles
Vehicle car1 = new Vehicle(1, "Toyota", "Camry", 2020, store1.getStoreID(), 100, "available", "car");
Vehicle bike1 = new Vehicle(2, "Honda", "CBR600", 2021, store2.getStoreID(), 50, "available", "bike");
VehicleInventory vehicleInventory = new VehicleInventory();
vehicleInventory.addVehicle(car1);
vehicleInventory.addVehicle(bike1);
// Create admin and customer
Admin admin = new Admin(1, "Admin", "admin@example.com", "password", "123-456-7890");
Customer customer = new Customer(2, "Customer", "customer@example.com", "password", "987-654-3210", "D1234567");
// Admin adds vehicles to stores
admin.addVehicle(car1, store1);
admin.addVehicle(bike1, store2);
// Customer searches for vehicles at a store
List<Vehicle> availableVehicles = customer.searchVehicle(store1);
// Customer books a vehicle
customer.bookVehicle(car1, new Date(), new Date(System.currentTimeMillis() + 86400000));
// Customer makes a payment
customer.makePayment(1, 100);
}
}






Comments