Advertisement
Iv555

Untitled

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