示例#1
0
        /// <summary>
        /// This menu shows when there are no available spots.
        /// </summary>
        public static void NoSpaces()
        {
            Console.WriteLine("There are no empty spots left, please wait until a vehicle has been checked out before trying again. " +
                              "\n Press any button to return to the main menu.");

            Console.ReadKey();
            Mainmenu.MainMenu();
        }
示例#2
0
        /// <summary>
        /// This menu shows when there is one or more full spot available.
        /// </summary>
        public static void AllChoises()
        {
            Console.Clear();
            Console.WriteLine("Park Vehicle. Please type the number of your menu choice" +
                              "\n \n 1. Park a bike" +
                              "\n \n 2. Park a motorcycle" +
                              "\n \n 3. Park a car" +
                              "\n \n 4. Park a bus" +
                              "\n \n 5. Return to the main menu" +
                              "\n");
            Console.Write("Number: ");
            string menuChoice = Console.ReadLine();

            int.TryParse(menuChoice, out int choice);

            if (choice >= 1 && choice <= 5)
            {
                switch (choice)
                {
                case 1: ParkingSpot.ParkVehicle("bike"); break;

                case 2: ParkingSpot.ParkVehicle("mc"); break;

                case 3: ParkingSpot.ParkVehicle("car"); break;

                case 4: ParkingSpot.ParkVehicle("bus"); break;

                case 5: Mainmenu.MainMenu(); break;

                default:
                    break;
                }
            }
            else
            {
                Console.WriteLine("Invalid input, try again");
                AllChoises();
            }
        }
示例#3
0
        /// <summary>
        /// This method is for the menu Check out vehicle.
        /// </summary>
        public static void CheckOut()
        {
            Console.Clear();
            Mainmenu.MenuPrinter();
            Console.Write("Please enter the registration number or the bikedescription of the vehicle you would like to check out: ");
            string regNr = Console.ReadLine().ToUpper();

            (Vehicle foundVehicle, ParkingSpot spot) = ParkingHouse.FindVehicle(regNr);

            if (spot is not null)
            {
                TimeSpan parkedTime;
                if (foundVehicle.type is not "Bus")
                {
                    spot.RemoveVehicle(foundVehicle);
                    //ParkingHouse.BackUp();
                    foundVehicle.TimeOut = DateTime.Now;
                    parkedTime           = foundVehicle.TimeOut - foundVehicle.timeIn;
                }
                else
                {
                    int removeSpot = spot.SpotNumber;
                    ParkingSpot.RemoveBus(foundVehicle, removeSpot);
                    //ParkingHouse.BackUp();
                    foundVehicle.TimeOut = DateTime.Now;
                    parkedTime           = foundVehicle.TimeOut - foundVehicle.timeIn;
                }
                if (parkedTime.Hours < 1)
                {
                    if (parkedTime.Minutes <= Initilizing.FreeMinutes)
                    {
                        Console.WriteLine($"\nThe parking for { foundVehicle.RegNr } is less than { Initilizing.FreeMinutes } minutes and is therefore without cost. " +
                                          $"\nThis vehicle has been checked out. \n\nPress any key to return to the main menu");
                        Console.ReadKey();
                        Mainmenu.MainMenu();
                    }
                    else
                    {
                        Console.WriteLine($"\nThe vehicle with the regnr { foundVehicle.RegNr } has been parked for more than { Initilizing.FreeMinutes } minutes but less than an hour. " +
                                          $"\nThe cost for this parking is { foundVehicle.cost } CZK. This vehicle has been checked out. \n\nPress any key to return to the main menu");
                        Console.ReadKey();
                        Mainmenu.MainMenu();
                    }
                }
                else
                {
                    if (parkedTime.Days < 30)
                    {
                        int parkedHours = parkedTime.Hours;
                        parkedHours += 1;
                        int startedDays  = parkedTime.Days;
                        int startedHours = parkedHours + (startedDays * 24);
                        int vehicleCost  = startedHours * foundVehicle.cost;

                        if (parkedTime.Days >= 1)
                        {
                            Console.WriteLine($"\nThe vehicle with the regnr { foundVehicle.RegNr } has been parked for { parkedTime.Days } day(s) and { parkedHours } started hours. " +
                                              $"\nThe cost for this parking is { vehicleCost } CZK. This vehicle has been checked out. \n\nPress any key to return to the main menu");
                            Console.ReadKey();
                            Mainmenu.MainMenu();
                        }
                        else
                        {
                            Console.WriteLine($"\nThe vehicle with the regnr { foundVehicle.RegNr } has been parked for { startedHours } started hours. " +
                                              $"\nThe cost for this parking is { vehicleCost } CZK. This vehicle has been checked out. \n\nPress any key to return to the main menu");
                            Console.ReadKey();
                            Mainmenu.MainMenu();
                        }
                    }
                    else
                    {
                        Console.WriteLine($"\nThe vehicle with the regnr { foundVehicle.RegNr } has been parked for more than a month. " +
                                          $"\nThe cost for this parking is on me :) This vehicle has been checked out. \n\nPress any key to return to the main menu");
                        Console.ReadKey();
                        Mainmenu.MainMenu();
                    }
                }
            }
            else if (regNr == "EXIT")
            {
                Mainmenu.MainMenu();
            }
            else
            {
                Console.WriteLine("There is no vehicle with that registration number, try again");
                Console.ReadKey();
                CheckOut();
            }
        }
示例#4
0
        /// <summary>
        /// This metod is for the menu choice "Search for and move vehicle"
        /// </summary>
        public static void MoveVehicle()
        {
            Console.Clear();
            Mainmenu.MenuPrinter();
            Console.Write("Please enter the registration number of the vehicle you would like to search for: ");
            string regNr = Console.ReadLine().ToUpper();

            if (regNr is not "EXIT")
            {
                (Vehicle foundVehicle, ParkingSpot oldSpot) = ParkingHouse.FindVehicle(regNr);
                if (foundVehicle is not null || oldSpot is not null)
                {
                    if (foundVehicle.type is not "Bus")
                    {
                        Console.Write($"\nThis vehicle is parked in spot { oldSpot.SpotNumber }, would you like to move it?: ");
                        string answer = Console.ReadLine().ToUpper();

                        if (answer == "Y" || answer == "YES")
                        {
                            Console.Write("Ok! Where would you like to park it instead?: ");
                            string spotAnswer = Console.ReadLine();
                            bool   correct    = int.TryParse(spotAnswer, out int spotSuggest);

                            if (correct)
                            {
                                ParkingSpot newSpot = ParkingHouse.FreeSpotFinder(foundVehicle.value, spotSuggest);
                                if (newSpot is not null)
                                {
                                    oldSpot.RemoveVehicle(foundVehicle);
                                    newSpot.Vehicles.Add(foundVehicle);
                                    newSpot.FreeSpace -= foundVehicle.value;
                                    Console.WriteLine($"\nThe { foundVehicle.type } with the registration number { foundVehicle.RegNr } " +
                                                      $"\nthat was parked in { oldSpot.SpotNumber } has been moved to { newSpot.SpotNumber }.");
                                    //ParkingHouse.BackUp();
                                }
                                else
                                {
                                    Console.WriteLine("This spot is not available." +
                                                      "\nNo changes have been made, please start over");
                                    Console.ReadKey();
                                    MoveVehicle();
                                }
                            }
                            else
                            {
                                Console.WriteLine("Incorrect input, please start from the beginning");
                                Console.ReadKey();
                                MoveVehicle();
                            }
                        }
                        else
                        {
                            Mainmenu.MainMenu();
                        }
                    }
                    else
                    {
                        Console.Write($"\nThis bus is parked in spot { oldSpot.SpotNumber } - { oldSpot.SpotNumber + 3 }, would you like to move it?: ");
                        string answer = Console.ReadLine().ToUpper();

                        if (answer == "Y" || answer == "YES")
                        {
                            Console.Write("Ok! It can only be parked somewhere in the first 50 spots." +
                                          "\nplease inser the number of the first spot of the four you would like to park it in: ");
                            string spotAnswer = Console.ReadLine();
                            bool   correct    = int.TryParse(spotAnswer, out int spotSuggest);

                            if (correct)
                            {
                                int         busSpace = foundVehicle.value / 4;
                                ParkingSpot newSpot  = ParkingHouse.FreeBusSpotFinder(spotSuggest);
                                if (newSpot is not null && spotSuggest < 47)
                                {
                                    int removeSpot = oldSpot.SpotNumber;
                                    ParkingSpot.RemoveBus(foundVehicle, removeSpot);

                                    ParkingHouse.ParkingSpots[spotSuggest - 1].FreeSpace -= busSpace;
                                    ParkingHouse.ParkingSpots[spotSuggest].FreeSpace     -= busSpace;
                                    ParkingHouse.ParkingSpots[spotSuggest + 1].FreeSpace -= busSpace;
                                    ParkingHouse.ParkingSpots[spotSuggest + 2].FreeSpace -= busSpace;

                                    ParkingHouse.ParkingSpots[spotSuggest - 1].Vehicles.Add(foundVehicle);
                                    ParkingHouse.ParkingSpots[spotSuggest].Vehicles.Add(foundVehicle);
                                    ParkingHouse.ParkingSpots[spotSuggest + 1].Vehicles.Add(foundVehicle);
                                    ParkingHouse.ParkingSpots[spotSuggest + 2].Vehicles.Add(foundVehicle);
                                    Console.WriteLine($"\nThe bus with the registration number { foundVehicle.RegNr } " +
                                                      $"\nthat was parked in { oldSpot.SpotNumber } - { oldSpot.SpotNumber + 3 } has been moved to { newSpot.SpotNumber } - { newSpot.SpotNumber + 3 }.");
                                    //ParkingHouse.BackUp();
                                }
                                else if (spotSuggest > 47)
                                {
                                    Console.WriteLine("Sorry, all spots above 50 have a too low ceiling to fit a bus");
                                }
                                else
                                {
                                    Console.WriteLine("This spot and the three following ones are not available." +
                                                      "\nNo changes have been made, please start over");
                                }
                            }
                            else
                            {
                                Console.WriteLine("Incorrect input, please start from the beginning");
                                Console.ReadKey();
                                MoveVehicle();
                            }
                        }
                        else
                        {
                            Mainmenu.MainMenu();
                        }
                    }