# 🚗 Building Vehicle Search System 🚗
## Objective
Design and implement a Vehicle Search System that allows users to search for vehicles based on specific criteria. The goal is to evaluate your skills in C# development, including object-oriented programming, LINQ, and optimization techniques.
## Skeleton Code
Use the following skeleton code as a starting point for your implementation:
```csharp
using System;
using System.Collections.Generic;
using System.Linq;
namespace VehicleSearchSystem;
public class Vehicle
{
public string Make { get; set; } // e.g., Toyota, Honda
public string Model { get; set; } // e.g., Corolla, Civic
public int Year { get; set; }
public string Color { get; set; }
public decimal Price { get; set; }
}
public class VehicleSearchService
{
private readonly List<Vehicle> _vehicles;
public VehicleSearchService(List<Vehicle> vehicles)
{
_vehicles = vehicles;
}
/// <summary>
/// Searches for vehicles based on optional filters.
/// </summary>
/// <param name="make">Filter by vehicle make (optional).</param>
/// <param name="model">Filter by vehicle model (optional).</param>
/// <param name="year">Filter by vehicle year (optional).</param>
/// <param name="maxPrice">Filter by maximum price (optional).</param>
/// <returns>A list of vehicles matching the criteria.</returns>
public List<Vehicle> SearchVehicles(string make = null, string model = null, int? year = null, decimal? maxPrice = null)
{
return _vehicles.Where(v =>
(string.IsNullOrEmpty(make) || v.Make.Equals(make, StringComparison.OrdinalIgnoreCase)) &&
(string.IsNullOrEmpty(model) || v.Model.Equals(model, StringComparison.OrdinalIgnoreCase)) &&
(!year.HasValue || v.Year == year.Value) &&
(!maxPrice.HasValue || v.Price <= maxPrice.Value))
.ToList();
}
}
public class Program
{
public static void Main(string[] args)
{
// Sample vehicle dataset
var vehicles = new List<Vehicle>
{
new Vehicle { Make = "Toyota", Model = "Corolla", Year = 2020, Color = "White", Price = 20000 },
new Vehicle { Make = "Honda", Model = "Civic", Year = 2021, Color = "Black", Price = 22000 },
new Vehicle { Make = "Ford", Model = "Mustang", Year = 2018, Color = "Red", Price = 26000 },
new Vehicle { Make = "Tesla", Model = "Model 3", Year = 2022, Color = "Blue", Price = 35000 }
};
var searchService = new VehicleSearchService(vehicles);
// Example of searching vehicles
Console.WriteLine("🔎 Search Results:");
var searchResults = searchService.SearchVehicles(make: "Toyota", maxPrice: 25000);
foreach (var vehicle in searchResults)
{
Console.WriteLine($"{vehicle.Make} {vehicle.Model}, Year: {vehicle.Year}, Color: {vehicle.Color}, Price: {vehicle.Price:C}");
}
}
}
```
## Requirements
1. Extend the Vehicle class to include an additional property: `Mileage` (in kilometers).
2. Update the `SearchVehicles` method to allow filtering by minimum mileage.
3. Add unit tests to ensure the functionality works as expected.
4. Optimize the `SearchVehicles` method to handle a larger dataset efficiently.
5. Refactor the program to support `async` searches.
## Bonus Tasks
1. Implement sorting (e.g., by price, year, or make) for search results.
2. Add support for pagination of search results.
3. Implement a more advanced search feature (e.g., fuzzy search, range search).