Advertisement
Guest User

Паркинг баце

a guest
Feb 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace SoftUniParking
  6. {
  7.     public class Parking
  8.     {
  9.         List<Car> Cars;
  10.         private int Capacity;
  11.  
  12.         public int Count
  13.         {
  14.             get { return this.Cars.Count; }
  15.         }
  16.  
  17.         public Parking(int capacity)
  18.         {
  19.             this.Cars = new List<Car>();
  20.             this.Capacity = capacity;
  21.         }
  22.  
  23.         public string AddCar(Car car)
  24.         {
  25.             if (!this.Cars.Contains(car))
  26.             {
  27.                 if (this.Cars.Count < this.Capacity)
  28.                 {
  29.                     this.Cars.Add(car);
  30.                     return $"Successfully added new car {car.Make} {car.RegistrationNumber}";
  31.                 }
  32.                 else
  33.                 {
  34.                     return "Parking is full!";
  35.                 }
  36.                
  37.             }
  38.             else
  39.             {
  40.                 return "Car with that registration number, already exists!";
  41.             }
  42.         }
  43.  
  44.         public string RemoveCar(string registrationNumber)
  45.         {
  46.             foreach (var car in this.Cars)
  47.             {
  48.                 if (car.RegistrationNumber == registrationNumber)
  49.                 {
  50.                     this.Cars.Remove(car);
  51.                     return $"Successfully removed {registrationNumber}";
  52.                 }
  53.             }
  54.  
  55.             return "Car with that registration number, doesn't exist!";
  56.         }
  57.  
  58.         public Car GetCar(string registrationNumber)
  59.         {
  60.             foreach (var car in this.Cars)
  61.             {
  62.                 if (car.RegistrationNumber == registrationNumber)
  63.                 {
  64.                     return car;
  65.                 }
  66.             }
  67.             return null;
  68.         }
  69.  
  70.         public void RemoveSetOfRegistrationNumber(List<string> registrationNumbers)
  71.         {
  72.             foreach (var number in registrationNumbers)
  73.             {
  74.                 RemoveCar(number);
  75.             }
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement