using System; using System.Collections.Generic; using System.Linq; public abstract class Vehicle { public int ID { get; private set; } public string Brand { get; private set; } public string Model { get; private set; } public bool IsRented { get; private set; } protected Vehicle(int id, string brand, string model) { ID = id; Brand = brand; Model = model; IsRented = false; } public void RentVehicle() { if (!IsRented) { IsRented = true; Console.WriteLine($"Vehicle {ID} has been rented."); } else { Console.WriteLine($"Vehicle {ID} is already rented."); } } public void ReturnVehicle() { if (IsRented) { IsRented = false; Console.WriteLine($"Vehicle {ID} has been returned."); } else { Console.WriteLine($"Vehicle {ID} is not currently rented."); } } public abstract void DisplayInfo(); } public class Car : Vehicle { public int NumberOfDoors { get; private set; } public Car(int id, string brand, string model, int numberOfDoors) : base(id, brand, model) { NumberOfDoors = numberOfDoors; } public override void DisplayInfo() { Console.WriteLine($"Car ID: {ID}, Brand: {Brand}, Model: {Model}, Doors: {NumberOfDoors}, Rented: {IsRented}"); } } public class Truck : Vehicle { public int LoadCapacity { get; private set; } public Truck(int id, string brand, string model, int loadCapacity) : base(id, brand, model) { LoadCapacity = loadCapacity; } public override void DisplayInfo() { Console.WriteLine($"Truck ID: {ID}, Brand: {Brand}, Model: {Model}, Load Capacity: {LoadCapacity}kg, Rented: {IsRented}"); } } public class Motorcycle : Vehicle { public bool HasSideCar { get; private set; } public Motorcycle(int id, string brand, string model, bool hasSideCar) : base(id, brand, model) { HasSideCar = hasSideCar; } public override void DisplayInfo() { Console.WriteLine($"Motorcycle ID: {ID}, Brand: {Brand}, Model: {Model}, Sidecar: {HasSideCar}, Rented: {IsRented}"); } } public static class VehicleUtils { public static double CalculateFine(int daysLate) { double dailyFine = 50.0; // فرض غرامة يومية return daysLate * dailyFine; } public static void DisplayRentalPolicy() { Console.WriteLine("Rental Policy: Late returns will incur a daily fine of $50."); } } public class VehicleOffice { private List vehicles = new List(); public void AddVehicle(Vehicle vehicle) { vehicles.Add(vehicle); } public void DisplayAllVehicles() { foreach (var vehicle in vehicles) { vehicle.DisplayInfo(); } } public Vehicle SearchVehicleById(int id) { return vehicles.FirstOrDefault(v => v.ID == id); } } class Program { static void Main(string[] args) { VehicleOffice office = new VehicleOffice(); // Adding Vehicles office.AddVehicle(new Car(1, "Toyota", "Corolla", 4)); office.AddVehicle(new Truck(2, "Ford", "F-150", 1000)); office.AddVehicle(new Motorcycle(3, "Harley-Davidson", "Street 750", false)); // Display all vehicles Console.WriteLine("All Vehicles:"); office.DisplayAllVehicles(); // Search for a vehicle and rent it Console.WriteLine("\nSearching for Vehicle with ID 1:"); Vehicle vehicle = office.SearchVehicleById(1); if (vehicle != null) { vehicle.RentVehicle(); vehicle.DisplayInfo(); // Returning the vehicle vehicle.ReturnVehicle(); vehicle.DisplayInfo(); } else { Console.WriteLine("Vehicle not found."); } // Display rental policy VehicleUtils.DisplayRentalPolicy(); // Example of calculating fine int daysLate = 3; // عدد الأيام المتأخرة double fine = VehicleUtils.CalculateFine(daysLate); Console.WriteLine($"Total fine for {daysLate} days late: ${fine}"); } }