コード例 #1
0
        public void ParkVehicle()
        {
            Console.WriteLine("Park a Car, MC, Bike or Bus");
            string VehicleChoise      = Console.ReadLine();
            string lowerVehiceChoise  = VehicleChoise.ToLower();
            string ValidVehicleChoise = DataValidation(lowerVehiceChoise);

            if (ValidVehicleChoise == null)
            {
                Console.WriteLine("Invalid Option.");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("Enter registration plate: ");
                string input = Console.ReadLine();
                input = input.ToUpper();
                string ValidRegPlate = DataValidation(input);
                if (ValidRegPlate == null)
                {
                    Console.WriteLine("Invalid Reg-Plate.");
                }
                switch (lowerVehiceChoise)
                {
                case "car":
                    Car car = new Car();
                    car.RegPlate   = input;
                    car.ArriveTime = DateTime.Now;

                    ParkingSpot spot;
                    spot = FindAvailableSpot(car);
                    if (spot != null)
                    {
                        spot.AddVehicle(car);
                        WriteToFile();
                        Console.WriteLine("Your car is now parked.");
                    }
                    else
                    {
                        Console.WriteLine("No empty spots available.");
                    }
                    Console.ReadKey();
                    break;

                case "mc":
                    MC newMC = new MC();
                    newMC.RegPlate   = input;
                    newMC.ArriveTime = DateTime.Now;

                    ParkingSpot Spot;
                    Spot = FindAvailableSpot(newMC);
                    if (Spot != null)
                    {
                        Spot.AddVehicle(newMC);
                        WriteToFile();
                        Console.WriteLine("Your Mc is now parked.");
                    }
                    else
                    {
                        Console.WriteLine("No spots available to park in, sorry.");
                    }
                    Console.ReadKey();
                    break;

                case "bike":
                    Bike bike = new Bike();
                    bike.RegPlate   = input;
                    bike.ArriveTime = DateTime.Now;

                    ParkingSpot spot1;
                    spot1 = FindAvailableSpot(bike);
                    if (spot1 != null)
                    {
                        spot1.AddVehicle(bike);
                        WriteToFile();
                        Console.WriteLine("Your bike is now parked.");
                        Console.ReadKey();
                    }
                    else
                    {
                        Console.WriteLine("No empty spots available.");
                    }
                    Console.ReadKey();
                    break;

                case "bus":
                    Bus bus = new Bus();
                    bus.RegPlate   = input;
                    bus.ArriveTime = DateTime.Now;

                    int placeToPark;
                    placeToPark = SpotAsInt();
                    if (placeToPark == 0 || placeToPark == -1)
                    {
                        Console.WriteLine("No empty spots available.");
                    }
                    else
                    {
                        for (int i = placeToPark; i < placeToPark + 4; i++)
                        {
                            parkingSpots[i].vehicles.Add(bus);
                            parkingSpots[i].AvailableSpace = 0;
                        }
                        WriteToFile();
                    }
                    Console.ReadKey();
                    break;
                }
            }
        }
コード例 #2
0
        public Vehicle RemoveAdd()
        {
            Console.WriteLine("Please insert the regnumber of the vehicle you wish to move!");
            string VehicleExit   = Console.ReadLine();
            string ValidRegPlate = DataValidation(VehicleExit);

            if (ValidRegPlate == null)
            {
                Console.WriteLine("Sorry, but a vehicle with that registration plate doesnt exist here.");
            }
            else
            {
                int index;
                foreach (var item in parkingSpots)
                {
                    foreach (Vehicle v in item.vehicles)
                    {
                        if (v.RegPlate.Equals(VehicleExit) && v.Size == settings.carSize)
                        {
                            index = parkingSpots.IndexOf(item);
                            Console.WriteLine($"Found at: {index}");
                            for (int i = 0; i < item.vehicles.Count; i++)
                            {
                                Console.WriteLine(item.vehicles[i]);
                            }
                            string checkin    = v.ArriveTime.ToString();
                            string TotalTime  = Vehicle.ExitTimeCalculator(checkin).ToString();
                            string TotalPrice = Vehicle.CalculateParkedTime(TotalTime, v.Size);
                            item.AvailableSpace += v.Size;
                            Car CarCopy = new Car();
                            CarCopy.RegPlate   = v.RegPlate;
                            CarCopy.Size       = v.Size;
                            CarCopy.ArriveTime = v.ArriveTime;
                            Car VehicleReturn = CarCopy;
                            item.vehicles.Remove(v);
                            return(VehicleReturn);
                        }
                        else if (v.RegPlate.Equals(VehicleExit) && v.Size == settings.mcSize)
                        {
                            index = parkingSpots.IndexOf(item);
                            Console.WriteLine($"Found at: {index}");
                            string checkin    = v.ArriveTime.ToString();
                            string TotalTime  = Vehicle.ExitTimeCalculator(checkin).ToString();
                            string TotalPrice = Vehicle.CalculateParkedTime(TotalTime, v.Size);
                            item.AvailableSpace += v.Size;
                            MC MCCopy = new MC();
                            MCCopy.RegPlate   = v.RegPlate;
                            MCCopy.Size       = v.Size;
                            MCCopy.ArriveTime = v.ArriveTime;
                            MC VehicleReturn = MCCopy;
                            item.vehicles.Remove(v);
                            return(VehicleReturn);
                        }
                        else if (v.RegPlate.Equals(VehicleExit) && v.Size == settings.bikeSize)
                        {
                            index = parkingSpots.IndexOf(item);
                            Console.WriteLine($"Found at: {index}");
                            string checkin    = v.ArriveTime.ToString();
                            string TotalTime  = Vehicle.ExitTimeCalculator(checkin).ToString();
                            string TotalPrice = Vehicle.CalculateParkedTime(TotalTime, v.Size);
                            item.AvailableSpace += v.Size;
                            Bike bikeCopy = new Bike();
                            bikeCopy.RegPlate   = v.RegPlate;
                            bikeCopy.Size       = v.Size;
                            bikeCopy.ArriveTime = v.ArriveTime;
                            Bike VehicleReturn = bikeCopy;
                            item.vehicles.Remove(v);
                            return(VehicleReturn);
                        }
                        else if (v.RegPlate.Equals(VehicleExit) && v.Size == settings.busSize)
                        {
                            index = parkingSpots.IndexOf(item);
                            Console.WriteLine($"Found at: {index}");
                            string checkin    = v.ArriveTime.ToString();
                            string TotalTime  = Vehicle.ExitTimeCalculator(checkin).ToString();
                            string TotalPrice = Vehicle.CalculateParkedTime(TotalTime, v.Size);
                            item.AvailableSpace += v.Size;
                            Bus busCopy = new Bus();
                            busCopy.RegPlate   = v.RegPlate;
                            busCopy.Size       = v.Size;
                            busCopy.ArriveTime = v.ArriveTime;
                            Bus VehicleReturn = busCopy;
                            item.vehicles.Remove(v);
                            return(VehicleReturn);
                        }
                    }
                }
                WriteToFile();
            }
            Console.ReadKey();
            return(null);
        }