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