Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Text;
- namespace Parking
- {
- public class Parking
- {
- private readonly List<Car> cars;
- public string Type { get; set; }
- public int Capacity { get; set; }
- public int Count => cars.Count;
- public Parking(string type, int capacity)
- {
- Type = type;
- Capacity = capacity;
- cars = new List<Car>();
- }
- public void Add(Car car)
- {
- if (cars.Count < Capacity)
- {
- cars.Add(car);
- }
- }
- public bool Remove(string manufacturer, string model)
- {
- Car car = cars.FirstOrDefault(x => x.Manufacturer == manufacturer && x.Model == model);
- if (cars.Contains(car))
- {
- cars.Remove(car);
- return true;
- }
- return false;
- }
- public Car GetLatestCar()
- {
- if (cars.Count == 0)
- {
- return null;
- }
- Car car = cars.OrderByDescending(x => x.Year).First();
- return car;
- }
- public Car GetCar(string manufacturer, string model)
- {
- Car car = cars.FirstOrDefault(x => x.Manufacturer == manufacturer && x.Model == model);
- //if (!(cars.Contains(car)))
- //{
- // return null;
- //}
- return car;
- }
- public string GetStatistics()
- {
- StringBuilder sb = new StringBuilder();
- sb.AppendLine($"The cars are parked in {Type}:");
- foreach (var car in cars)
- {
- sb.AppendLine(car.ToString());
- }
- return sb.ToString().TrimEnd();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement