/// <summary> /// Add car on parking WITHOUT starting balance. /// </summary> /// <param name="carType">Type of car</param> public void AddCar(CarTypes carType) { bool freeParkingPlace = IsThereFreeParkingPlace(); int numberOfFreeParkingPlace = 0; if (freeParkingPlace) { for (int i = 0; i < FreeParkingPlacesList.Count; i++) { if (FreeParkingPlacesList[i] == true) { numberOfFreeParkingPlace = i; break; } } ListOfCars.Add(new Car(carType, numberOfFreeParkingPlace)); FreeParkingPlacesList[numberOfFreeParkingPlace] = false; } else { throw new NoFreeParkingPlacesException("No free parking places!"); } }
/// <summary> /// Delete a car by id. /// </summary> /// <param name="idOfCar">Id of car.</param> public void DeleteCarById(int idOfCar) { int counterOfId = 0; foreach (Car item in ListOfCars) { if (item.Id == idOfCar) { break; } else { counterOfId++; } } if (counterOfId >= ListOfCars.Count) { throw new IdOfCarDoesNotExistException("Id of car does not exist!"); } if (ListOfCars[counterOfId].Balance < 0) { throw new CarBalanceLessZeroException("You can`t delete the car. Balance less zero!"); } FreeParkingPlacesList[ListOfCars[counterOfId].NumberOfParkingPlace] = true; ListOfCars.RemoveAt(counterOfId); }
public void AddCar(double balance, CarType type) { ListOfCars.Add(new Car(balance, type)); var id = ListOfCars[ListOfCars.Count - 1].Id; Console.WriteLine("The car was added successfully! Car id: " + id); _dictTimers.Add(ListOfCars[ListOfCars.Count - 1], new Timer(_tcbTrans, id, _settings.TimeOut * 1000, _settings.TimeOut * 1000)); }
public void RemoveSetOfRegistrationNumber(List <string> registrationNumbers) { foreach (var regPlate in registrationNumbers) { if (ListOfCars.Any(x => x.RegistrationNumber == regPlate)) { Car car = ListOfCars.Find(x => x.RegistrationNumber == regPlate); ListOfCars.Remove(car); } } Count = ListOfCars.Count; }
public string RemoveCar(string registrationNumber) { if (!ListOfCars.Any(x => x.RegistrationNumber == registrationNumber)) { return("Car with that registration number, doesn't exist!"); } else { Car carForRemove = ListOfCars.Find(x => x.RegistrationNumber == registrationNumber); ListOfCars.Remove(carForRemove); Count = ListOfCars.Count; return($"Successfully removed {registrationNumber}"); } }
public string AddCar(Car car) { if (ListOfCars.Any(x => x.RegistrationNumber == car.RegistrationNumber)) { return("Car with that registration number, already exists!"); } else if (ListOfCars.Count >= this.capacity) { return("Parking is full!"); } ListOfCars.Add(car); Count = ListOfCars.Count; return($"Successfully added new car {car.Make} {car.RegistrationNumber}"); }
private void Transaction(object obj) { var id = (int)obj; var indexOfCar = ListOfCars.FindIndex(car => car.Id == id); double priceOfTrans = _settings.Prices[ListOfCars[indexOfCar].Type]; if (priceOfTrans > ListOfCars[indexOfCar].Balance) { priceOfTrans *= _settings.Fine; ListOfCars[indexOfCar].Fine += priceOfTrans; } else { ListOfCars[indexOfCar].Balance -= priceOfTrans; Income += priceOfTrans; ListOfTransactions.Add(new Transaction(id, priceOfTrans)); } }
/// <summary> /// Delete a car by number of parking place. /// </summary> /// <param name="numberOfParkingPlace">Number of parking place where is located the car which user wants to delete.</param> public void DeleteCarByNumberOfParkingPlace(int numberOfParkingPlace) { //numberOfParkingPlace = 0, 1, 2, ..., Settings.ParkingSpace - 1 if (numberOfParkingPlace > Settings.ParkingSpace - 1) { throw new NumberOfParkingPlaceDoesNotExistException("Number of parking place does not exist!"); } if (FreeParkingPlacesList[numberOfParkingPlace]) { throw new ParkingPlaceIsFreeException("We can`t delete a car! Parking place is already free!"); } int counterOfDeleteCar = 0; foreach (Car item in ListOfCars) { if (item.NumberOfParkingPlace != numberOfParkingPlace) { counterOfDeleteCar++; } else { break; } } if (ListOfCars[counterOfDeleteCar].Balance < 0) { throw new CarBalanceLessZeroException("You can`t delete the car. Balance less zero!"); } //Можна доробити, щоб при видаленні машини спрацьовував метод Dispose() класу Car. Тоді будуть вивільнятися id видалених //і вони будуть використані для створення нових машин. ListOfCars.RemoveAt(counterOfDeleteCar); FreeParkingPlacesList[numberOfParkingPlace] = true; }
public Car GetCar(string registrationNumber) { Car carToGet = ListOfCars.Find(x => x.RegistrationNumber == registrationNumber); return(carToGet); }