Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace SoftUniParking
- {
- public class Parking
- {
- List<Car> Cars;
- private int Capacity;
- public int Count
- {
- get { return this.Cars.Count; }
- }
- public Parking(int capacity)
- {
- this.Cars = new List<Car>();
- this.Capacity = capacity;
- }
- public string AddCar(Car car)
- {
- if (!this.Cars.Contains(car))
- {
- if (this.Cars.Count < this.Capacity)
- {
- this.Cars.Add(car);
- return $"Successfully added new car {car.Make} {car.RegistrationNumber}";
- }
- else
- {
- return "Parking is full!";
- }
- }
- else
- {
- return "Car with that registration number, already exists!";
- }
- }
- public string RemoveCar(string registrationNumber)
- {
- foreach (var car in this.Cars)
- {
- if (car.RegistrationNumber == registrationNumber)
- {
- this.Cars.Remove(car);
- return $"Successfully removed {registrationNumber}";
- }
- }
- return "Car with that registration number, doesn't exist!";
- }
- public Car GetCar(string registrationNumber)
- {
- foreach (var car in this.Cars)
- {
- if (car.RegistrationNumber == registrationNumber)
- {
- return car;
- }
- }
- return null;
- }
- public void RemoveSetOfRegistrationNumber(List<string> registrationNumbers)
- {
- foreach (var number in registrationNumbers)
- {
- RemoveCar(number);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement