Exemple #1
0
        public string CheckIn(string RegistrationNumber, VehicleType aVehicleType)
        {
            Vehicle vehicle = CreateVehicle(aVehicleType);

            vehicle.RegNumber = RegistrationNumber;
            ParkingPlace place = SearchPlaceWhereVehicleIsParked(RegistrationNumber);

            if (place != null)
            {
                throw new EVehicleAlreadyCheckedIn(RegistrationNumber, place.ID);
            }
            try
            { //If there is no available space for this type of car, an exception is raised (sequence contains no elements)
                place = parkingPlaces.Where(pl => pl.VehicleType == vehicle.VehicleType)
                        .Where(pl => !pl.Occupied)
                        .First();
            }
            catch (Exception)
            {// Throw our own exception with a custom message text
                throw new ENoPlaceForVehicle(aVehicleType.ToString());
            }
            place.Park(vehicle);

            return(place.ID);
        }
Exemple #2
0
        private static void CheckOut()
        {
            Console.WriteLine("Check out\nWhat is the registration number of the car you want to check out?");
            string regNr = Console.ReadLine();

            try
            {
                ParkingPlace place = garage.SearchPlaceWhereVehicleIsParked(regNr);
                if (place == null)
                {
                    Console.WriteLine("Cannot find the vehicle with registration numner '{0}'", regNr);
                    Console.ReadKey();
                }
                else
                {
                    Console.WriteLine("The vehicle is parked at {0}. Price is SEK {1}", place.ID, place.Vehicle.Price);
                    switch (ConstrainInput("Do you want to checkout y/n?", new string[] { "y", "n" }))
                    {
                    case "y":
                        garage.CheckOut(regNr);
                        break;

                    case "n":
                        return;
                    }
                }
            }

            catch (EVehicleNotFound e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemple #3
0
        public void CheckOut(string RegistrationNumber)
        {
            ParkingPlace place = SearchPlaceWhereVehicleIsParked(RegistrationNumber);

            if (place == null)
            {
                throw new EVehicleNotFound(RegistrationNumber);
            }
            place.Unpark();
        }
Exemple #4
0
        private static void Checkin()
        {
            Console.WriteLine("Check in a vehicle");
            string regNumber = "";

            while (regNumber == "")
            {
                Console.WriteLine("Please enter the registration Number");
                regNumber = Console.ReadLine();
            }
            ParkingPlace place = garage.SearchPlaceWhereVehicleIsParked(regNumber);

            if (place != null) //Check if vehicle is already parked in order to avoid asking for vehicle type if we cannot check in anyway.
            {
                Console.WriteLine("Your vehicle is already parked. See details below:\n{0}\nPlease press any key to return to the main menu.", place.Vehicle.ToString());
                Console.ReadKey();
                return;
            }

            Console.WriteLine("Please choose what vehicle Type");
            Console.WriteLine("1) Motorcycle\n2) Car\n3) Bus\n4) Truck");

            string input = ConstrainInput("Type: ", new string[] { "1", "2", "3", "4" });

            VehicleType vt;

            switch (input)
            {
            case "1":
                vt = VehicleType.Motorcycle;
                break;

            case "2":
                vt = VehicleType.Car;
                break;

            case "3":
                vt = VehicleType.Bus;
                break;

            default:
                vt = VehicleType.Truck;
                break;
            }

            try
            {
                Console.WriteLine("{0} with registration number {1} is now checked in at place {2}.", vt, regNumber, garage.CheckIn(regNumber, vt));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.ReadKey();
        }
Exemple #5
0
        public Vehicle SearchVehicle(string aRegistrationNumber)
        {
            ParkingPlace park = SearchPlaceWhereVehicleIsParked(aRegistrationNumber);

            if (park == null)
            {
                return(null);
            }
            else
            {
                return(park.Vehicle);
            }
        }
Exemple #6
0
        private static void SearchVehicle()
        {
            Console.WriteLine("Please enter your vehicle's registration number.");
            string regNr = Console.ReadLine();

            try
            {
                ParkingPlace place = garage.SearchPlaceWhereVehicleIsParked(regNr);
                if (place == null)
                {
                    Console.WriteLine("Cannot find the vehicle with registration number '{0}'", regNr);
                }
                else
                {
                    Console.WriteLine("The vehicle is parked at {0}.\n{1}", place.ID, place.Vehicle.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.ReadKey();
        }