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.Text;
- namespace Parking
- {
- public class Parking
- {
- private List<Car> data;
- public string Type { get; set; }
- public int Capacity { get; set; }
- public int Count => data.Count;
- public Parking(string type,int capacity)
- {
- this.Type = type;
- this.Capacity = capacity;
- data = new List<Car>();
- }
- public void Add(Car car)
- {
- if (Capacity > Count)
- {
- data.Add(car);
- }
- }
- public bool Remove(string manufacturer, string model)
- {
- Car manufacturerToRemove = data.FirstOrDefault(x => x.Manufacturer == manufacturer);
- Car modelToRemove = data.FirstOrDefault(x => x.Model == model);
- return data.Remove(modelToRemove);
- }
- public Car GetLatestCar()
- {
- if (Count == 0)
- {
- return null;
- }
- else
- {
- Car GetLatestCar = data.OrderByDescending(x => x.Year).FirstOrDefault();
- return GetLatestCar;
- }
- }
- public Car GetCar(string manufacturer,string model)
- {
- Car manufacturerToGet = data.FirstOrDefault(x => x.Manufacturer == manufacturer);
- Car modelToGet = data.FirstOrDefault(x => x.Manufacturer == model);
- Car GetLatestCar = data.OrderByDescending(x => x.Year).FirstOrDefault();
- return manufacturerToGet;
- }
- public string GetStatistics()
- {
- StringBuilder sb = new StringBuilder();
- sb.AppendLine($"The cars are parked in {Type}:");
- foreach (var car in data)
- {
- sb.AppendLine(car.ToString());
- }
- return sb.ToString().TrimEnd();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement