Advertisement
Guest User

Parking.cs

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