/// <summary> /// Finding a suitable ticket type and the cost differnce from original ticket type. /// Iterate the ticket types until finding a ticket type that validates the vehicle. /// </summary> /// <param name="vehicle"></param> /// <param name="rank"></param> /// <returns></returns> public CheckInResult FindMatchingTicket(Vehicle vehicle, TicketRank rank) { TicketType coresspondTicket = TicketTypes[rank]; int initialCost = coresspondTicket.Price; // find corresponding ticketType do { rank++; coresspondTicket = TicketTypes[rank]; } while (TicketTypes.ContainsKey(rank) && !coresspondTicket.IsVehicleSuitable(vehicle)); if (!TicketTypes.ContainsKey(rank)) { rank = TicketRank.Undefined; } return(new CheckInResult(rank.ToString(), coresspondTicket.Price - initialCost, false, -1, vehicle.VehicleName)); }