class Garage
{
private List<Car> cars;
public void AddCar(string carModel, string color, double speed, int yearOfIssue)
{
Car car = new Car(carModel, color, speed, yearOfIssue);
cars.Add(car);
}
public void DeleteCar(string carModel, string color, double speed, int yearOfIssue)
{
}
}
class Car
{
public Car()
{
}
public Car(string carModel, string color, double speed, int yearOfIssue)
{
this.carModel = carModel;
this.color = color;
this.speed = speed;
this.yearOfIssue = yearOfIssue;
}
private string carModel;
private string color;
private double speed;
private int yearOfIssue;
}
public class Garage
{
public Garage()
{
_cars = new List<Car>();
}
private readonly List<Car> _cars;
public void AddCar(string carModel, string color, double speed, int yearOfIssue)
{
var car = new Car(carModel, color, speed, yearOfIssue);
_cars.Add(car);
}
public void DeleteCar(string carModel, string color = "", double speed = 0, int yearOfIssue = 0)
{
var query = from c in _cars
where c.CarModel.StartsWith(carModel)
select c;
if (color != string.Empty)
query = query.Where(cl => cl.Color == color);
if (speed > 0)
query = query.Where(sp => Math.Abs(sp.Speed - speed) < 0.2);
if (yearOfIssue > 0)
query = query.Where(y => y.YearOfIssue == yearOfIssue);
var results = query.Select(f => f).ToList();
foreach (var car in results) _cars.Remove(car);
}
}
public class Car
{
public Car()
{
}
public Car(string carModel, string color, double speed, int yearOfIssue)
{
this._carModel = carModel;
this._color = color;
this._speed = speed;
this._yearOfIssue = yearOfIssue;
}
private string _carModel;
public string CarModel => _carModel;
private string _color;
public string Color => _color;
private double _speed;
public double Speed => _speed;
private int _yearOfIssue;
public int YearOfIssue => _yearOfIssue;
}
public void DeleteCar(string carModel, string color, double speed, int yearOfIssue)
{
Car car = cars.FirstOrDefault(c => c.CarModel == carModel && c.Color == color && c.Speed == speed && c.YearOfIssue == yearOfIssue);
cars.Remove(car);
}