public ParkingTicket Park(Car car) { Printer printer = new Printer(); if (car == null) { printer.PrintNullCarErrorMessage(); return(null); } ParkingTicket parkingTicket = null; foreach (var parkingLot in ManagedParkingLots) { parkingTicket = parkingLot.Park(car); if (parkingTicket == null) { continue; } UpdateProvidedParkingTicket(parkingTicket); break; } return(parkingTicket); }
public Car FetchCar(ParkingTicket parkingTicket, out string errorMessage) { Car car = null; if (parkingTicket == null) { errorMessage = "Please provide your parking ticket."; return(null); } if (parkingTicket.IsUsed) { errorMessage = "Unrecognized parking ticket."; return(null); } foreach (var parkedCar in parkedCars) { if (parkedCar.Key.CarId == parkingTicket.CarId) { parkingTicket.IsUsed = true; car = parkedCar.Key; } } errorMessage = string.Empty; Car outCar = car; parkedCars.Remove(car); return(outCar); }
public override string ParkVehicle(string[] command_parts) { //Check if slots available if (parkingLot.Slots_available.Count > 0) { string id = command_parts[1]; //Check if a duplicate/illegal car is being parked if (parkingLot.Registration_Lookup != null && parkingLot.Registration_Lookup[id].Count() > 0) { return("Duplicate/Illegal car being parked"); } //Create a Vehicle, a ticket and update the slots int age = Convert.ToInt32(command_parts[3]); var vehicle = new Vehicle(id, age); int slot = parkingLot.Slots_available.First(); var ticket = new ParkingTicket(vehicle, slot); parkingLot.Slots_available.Remove(slot); parkingLot.Slots_not_available.Add(slot); //Add ticket to parking lot and setup lookups for quick querying parkingLot.Tickets.Add(ticket); parkingLot.Age_Lookup = (Lookup <int, ParkingTicket>)parkingLot.Tickets.ToLookup(x => x.Vehicle.Driver_Age); parkingLot.Registration_Lookup = (Lookup <string, ParkingTicket>)parkingLot.Tickets.ToLookup(x => x.Vehicle.RegistrationId); //Return result return("Car with vehicle registration numner \"" + id + "\" has been parked at slot number " + ticket.SlotId); } else { return("Parking lot full!!"); } }
public double GetParkingFee(ParkingTicket ticket) { var totalHours = (DateTime.Now - ticket._issueDateTime).TotalHours; var rates = Lot.GetParkingRates(); var firstHourRate = rates[rates.Keys.FirstOrDefault <int>()]; if (totalHours <= firstHourRate) { return(firstHourRate); // first rate hour } Double totalAmount = 0; var count = 0; foreach (var key in rates.Keys) { if (key == 0) // default amount after 2 hours. { totalAmount = totalAmount + rates[key] * (totalHours - count); break; } var currentHourRate = rates[key]; totalAmount = totalAmount + currentHourRate; count++; } return(totalAmount); }
public Car Fetch(ParkingTicket parkingTicket) { Printer printer = new Printer(); if (parkingTicket == null) { printer.PrintMissingParkingTicketErrorMessage(); return(null); } if (!IsProvidedParkingTicket(parkingTicket) || parkingTicket.GetIsUsed()) { printer.PrintWrongParkingTicketErrorMessage(); return(null); } Car fetchedCar = parkingTicket.GetParkingLot().Fetch(parkingTicket); if (fetchedCar != null) { parkingTicket.UseTicket(); } UpdateProvidedParkingTicket(parkingTicket); return(fetchedCar); }
public Car FetchCarFromParkingBoy(ParkingBoy parkingBoy, ParkingTicket parkingTicket) { var resultCar = parkingBoy.FetchCar(parkingTicket, out var errorMessage); AddMessage(errorMessage); return(resultCar); }
public Car Fetch(ParkingTicket parkingTicket) { if (cars.ContainsKey(parkingTicket.GetCarPlateNumber())) { return(cars[parkingTicket.GetCarPlateNumber()]); } return(null); }
public ParkingTicket GetParkingTicket(Vehicle vehicle) { var ticket = new ParkingTicket(vehicle); var spot = FindParkingSpotInAnyFloors(vehicle); ticket.Spot = spot; spot.Floor.AssignSpot(spot, vehicle); ticket.Save(); return(ticket); }
public ICar FetchCar(ParkingTicket parkingTicket, out string errorMessage) { if (!IsInputParkingTicketValid(parkingTicket, out errorMessage)) { return(null); } var parkingLot = this.parkingLotList.FirstOrDefault(parkingLot => parkingLot.ParkingLotId == parkingTicket.ParkingLotId); errorMessage = null; return(parkingLot.GetCar(parkingTicket.CarId)); }
public bool ProcessPayment(ParkingTicket ticket, Payment payment) { var result = payment.ProcessPayment(); if (result) { ticket.Status = ParkingTicketStatus.Paid; ticket.Spot.Floor.ReleseSpot(ticket.Spot); ticket.Save(); return(true); } return(false); }
public new ParkingTicket Park(Car car) { Printer printer = new Printer(); if (car == null) { printer.PrintNullCarErrorMessage(); return(null); } ManagedParkingLots.Sort((x, y) => y.GetCapacity() - y.GetCars().Count - (x.GetCapacity() - x.GetCars().Count)); ParkingTicket parkingTicket = ManagedParkingLots[0].Park(car); if (parkingTicket != null) { UpdateProvidedParkingTicket(parkingTicket); } return(parkingTicket); }
public ParkingTicket ParkingCar(Car car, out string errorMessage) { if (car == null) { errorMessage = "Input car is null."; } if (leftPosition <= 0) { errorMessage = "Not enough position."; return(null); } ParkingLot parkingLot = new ParkingLot("A"); errorMessage = string.Empty; ParkingTicket parkingTicket = new ParkingTicket(car.CarId, parkingLot); parkedCars.Add(car, parkingLot); leftPosition--; return(parkingTicket); }
private bool IsInputParkingTicketValid(ParkingTicket parkingTicket, out string errorMessage) { if (parkingTicket is null) { errorMessage = "Please provide your parking ticket."; failOperation?.Invoke(errorMessage); return(false); } if (this.parkingLotList.Where(parkingLot => parkingLot.ParkingLotId == parkingTicket.ParkingLotId).ToList().Count == 0) { errorMessage = "Unrecognized parking ticket."; failOperation?.Invoke(errorMessage); return(false); } var parkingLot = this.parkingLotList.FirstOrDefault(parkingLot => parkingLot.ParkingLotId == parkingTicket.ParkingLotId); if (!parkingLot.IsCarIdProvided(parkingTicket.CarId)) { errorMessage = "Unrecognized parking ticket."; failOperation?.Invoke(errorMessage); return(false); } if (!parkingLot.HasCarId(parkingTicket.CarId)) { errorMessage = "Unrecognized parking ticket."; failOperation?.Invoke(errorMessage); return(false); } errorMessage = null; return(true); }
private bool IsProvidedParkingTicket(ParkingTicket parkingTicket) { return(this.providedParkingTickets.ContainsKey(parkingTicket.GetParkingTime())); }
protected void UpdateProvidedParkingTicket(ParkingTicket parkingTicket) { this.providedParkingTickets.TryAdd(parkingTicket.GetParkingTime(), parkingTicket); }
public Car FetchCarByParkingBoy(ParkingTicket parkingTicket, ParkingBoy parkingBoy, out string errorMessage) { return(parkingBoy.FetchCar(parkingTicket, out errorMessage)); }
public void GetParkingBoyToFetch(ParkingTicket parkingTicket) { managedParkingBoys[0].Fetch(parkingTicket); }
public void AssignTicket(ParkingTicket ticket, Vehicle vehicle) { throw new NotImplementedException(); }
public ParkingSpot ReleaseSpot(ParkingTicket ticket, ParkingSpot spot) { throw new NotImplementedException(); }