Advertisement
Yanislav29

Untitled

Jun 28th, 2020
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography.X509Certificates;
  5. using System.Text;
  6.  
  7. namespace Parking
  8. {
  9. public class Parking
  10. {
  11.  
  12. private List<Car> cars;
  13.  
  14. public Parking(string type, int capacity)
  15. {
  16. this.Type = type;
  17. this.Capacity = capacity;
  18. cars = new List<Car>();
  19. }
  20. public string Type { get; set; }
  21.  
  22. public int Capacity { get; set; }
  23.  
  24. public int Count => cars.Count;
  25.  
  26. public void Add(Car car)
  27. {
  28. if (cars.Count < this.Capacity)
  29. {
  30. cars.Add(car);
  31. }
  32. }
  33. public bool Remove(string manufacturer, string model)
  34. {
  35. if (cars.Any(x => x.Manufacturer == manufacturer && x.Model == model))
  36. {
  37.  
  38. Car car = cars.Find(x => x.Manufacturer == manufacturer && x.Model == model);
  39. cars.Remove(car);
  40. return true;
  41. }
  42. return false;
  43. }
  44. public Car GetLatestCar()
  45. {
  46. if (cars.Count == 0) return null;
  47. int max = 0;
  48. Car car = new Car();
  49. foreach (var item in cars)
  50. {
  51. if(item.Year > max)
  52. {
  53. max = item.Year;
  54. car = item;
  55. }
  56. }
  57.  
  58. return car;
  59. }
  60.  
  61. public Car GetCar(string manufacturer, string model)
  62. {
  63. if (cars.Any(x => x.Manufacturer == manufacturer && x.Model == model))
  64. {
  65.  
  66. Car car = cars.Find(x => x.Manufacturer == manufacturer && x.Model == model);
  67.  
  68. return car;
  69. }
  70. return null;
  71. }
  72. public string GetStatistics()
  73. {
  74. return $"The cars are parked in {this.Type}: {string.Join(Environment.NewLine, cars)}";
  75. }
  76. }
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement