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.Security.Cryptography.X509Certificates;
- using System.Text;
- namespace Parking
- {
- public class Parking
- {
- private List<Car> cars;
- public Parking(string type, int capacity)
- {
- this.Type = type;
- this.Capacity = capacity;
- cars = new List<Car>();
- }
- public string Type { get; set; }
- public int Capacity { get; set; }
- public int Count => cars.Count;
- public void Add(Car car)
- {
- if (cars.Count < this.Capacity)
- {
- cars.Add(car);
- }
- }
- public bool Remove(string manufacturer, string model)
- {
- if (cars.Any(x => x.Manufacturer == manufacturer && x.Model == model))
- {
- Car car = cars.Find(x => x.Manufacturer == manufacturer && x.Model == model);
- cars.Remove(car);
- return true;
- }
- return false;
- }
- public Car GetLatestCar()
- {
- if (cars.Count == 0) return null;
- int max = 0;
- Car car = new Car();
- foreach (var item in cars)
- {
- if(item.Year > max)
- {
- max = item.Year;
- car = item;
- }
- }
- return car;
- }
- public Car GetCar(string manufacturer, string model)
- {
- if (cars.Any(x => x.Manufacturer == manufacturer && x.Model == model))
- {
- Car car = cars.Find(x => x.Manufacturer == manufacturer && x.Model == model);
- return car;
- }
- return null;
- }
- public string GetStatistics()
- {
- return $"The cars are parked in {this.Type}: {string.Join(Environment.NewLine, cars)}";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement