private void FindVehiclesByProporties()
        {
            Console.Clear();

            ui.Print("Please enter the color of the vehicles you would like to find!");
            var color = ui.GetInput();

            ui.Print("Please enter the number of wheels of the vehicles you would like to find!");
            var NrOfWheels = ui.GetInput();

            ui.Print("Please enter the type of the vehicle would like to find!");
            var type = ui.GetInput();
            IEnumerable <Vehicle> result = handler.GetAll();

            if (!string.IsNullOrWhiteSpace(color))
            {
                result = result.Where(v => v.Color.Equals(color, StringComparison.InvariantCultureIgnoreCase));
            }

            if (!String.IsNullOrWhiteSpace(NrOfWheels) && int.TryParse(NrOfWheels, out int getWheelsNr))
            {
                result = result.Where(v => v.NrOfWheels == getWheelsNr);
            }


            if (!String.IsNullOrWhiteSpace(type))
            {
                result = result.Where(v => v.GetType().Name.Equals(type, StringComparison.InvariantCultureIgnoreCase));
            }

            foreach (var itemAllVehicles in result)
            {
                if (color.ToLower() == itemAllVehicles.Color.ToLower() || type.ToLower() == itemAllVehicles.GetType().Name.ToLower() || int.TryParse(NrOfWheels, out getWheelsNr))
                {
                    Console.Clear();
                    ui.Print($"A vehicle of type {itemAllVehicles.GetType().Name} with the register number: {itemAllVehicles.RegNr} that has a {itemAllVehicles.Color} color and {itemAllVehicles.NrOfWheels} wheels has been found");
                }
                else
                {
                    Console.Clear();
                    ui.Print("No vehicles found in these specifications!");
                    break;
                }
            }
        }
Exemple #2
0
        public void PrintMenu()
        {
            do
            {
                ui.Print("1. Populate the garage with som vehicles " +
                         "\n2. Print all vehicles in the garage " +
                         "\n3. Print vehicle types and how many of each there are in the garage" +
                         "\n4. Park a vehicle " +
                         "\n5. Pick up a vehicle" +
                         "\n6. Get information about the vehicle by giving the registration number" +
                         "\n7. Get a group of vehicles with certain attributes" +
                         "\nQ. Quit application");
                switch (ui.GetInput())
                {
                case "1":
                    SeedData();
                    break;

                case "2":
                    PrintAll();
                    break;

                case "3":
                    PrintVehicleTypes();
                    break;

                case "4":
                    Park();
                    break;

                case "5":
                    PickUp();
                    break;

                case "6":
                    FindVehicleWithRegNr();
                    break;

                case "7":
                    FindVehicle();

                    break;

                case "Q":
                    Environment.Exit(0);
                    break;

                default:
                    ui.Print("Wrong choice, try again");
                    break;
                }
                ;
            } while (true);
        }
Exemple #3
0
        internal static string AskForAlphabets(string prompt, IUI ui)
        {
            bool   success = false;
            string answer;

            do
            {
                ui.Print(prompt);
                answer = ui.GetInput();

                if (!string.IsNullOrEmpty(answer) && Regex.IsMatch(answer, @"^[a-zA-Z]+$"))
                {
                    success = true;
                }
            } while (!success);

            return(answer);
        }
Exemple #4
0
        internal static string AskForString(string prompt, IUI ui)

        {
            bool   success = false;
            string answer;

            do
            {
                ui.Print(prompt);
                answer = ui.GetInput();

                if (!string.IsNullOrEmpty(answer))
                {
                    success = true;
                }
            } while (!success);

            return(answer);
        }
    {//Prompt = det vi vill skriva ut på skärmen
        //Ui hanterar utskrift
        public static string AskForString(string prompt, IUI ui)
        {
            bool   success = false;
            string answer;

            //loopa tills användaren har skrivit in något
            //Än så länge ingen annan validering
            do
            {
                Console.WriteLine(prompt);
                answer = ui.GetInput();

                if (String.IsNullOrWhiteSpace(answer))
                {
                    ui.Print("You must enter something");
                }
                else
                {
                    success = true;
                }
            } while (!success);

            return(answer);
        }
Exemple #6
0
 public string Input(IScreen screen)
 {
     return(_ui.GetInput());
 }
Exemple #7
0
        public void AddVehicleByOption()
        {
            var list = garageHandler.garage.Vehicles;

            ui.Print("Välj vilket fordon du vill lägga till? "
                     + "\n1. Airplane "
                     + "\n2. MotorCycle"
                     + "\n3. Car"
                     + "\n4. Bus"
                     + "\n5. Boat"
                     + "\n6 Exit");

            string option = ui.GetInput();

            if (garageHandler.garage.IsFull())
            {
                ui.Print("Garage is now full");
            }
            else
            {
                switch (option)
                {
                case "1":
                    AddAirplane();
                    ui.Print(" ");
                    ui.Print("Airplane is parked");
                    ui.Print(" ");
                    break;

                case "2":
                    AddMotorcycle();
                    ui.Print(" ");
                    ui.Print("Motorcycle is parked");
                    ui.Print(" ");
                    break;

                case "3":
                    AddCar();
                    ui.Print(" ");
                    ui.Print("Car is parked");
                    ui.Print(" ");
                    break;

                case "4":
                    AddBus();
                    ui.Print(" ");
                    ui.Print("Bus is parked");
                    ui.Print(" ");
                    break;

                case "5":
                    AddBoat();
                    ui.Print(" ");
                    ui.Print("Boat is parked");
                    ui.Print(" ");
                    break;

                case "6":
                    Environment.Exit(0);
                    break;

                default:
                    ui.WrongInput("Wrong input, you must choose 1, 2, 3, 4 or 5");
                    break;
                }
            }
        }
Exemple #8
0
        private void SearchVehicleProperties()
        {
            var    vList       = garageHandler.garage.Vehicles;
            string inputType   = "";
            string inputColor  = "";
            int    inputWheels = -1;
            var    searchStr   = "Please search vehicle through the menu by inputting " +
                                 "the number \n(1, 2, 3 ,4, 0) of your choice "

                                 + "\n1. Search by color"
                                 + "\n2. Search by number of wheels"
                                 + "\n3. Search by type";


            var userString  = "Search?: ";
            var searchAgain = "Search again?: \n1. Yes \n2. No, display search result";

            bool isSearchOk = true;

            do
            {
                ui.Print(searchStr);
                string userInput = ui.GetInput();

                switch (userInput)
                {
                case "1":
                    ui.Print(userString);
                    inputType = ui.GetInput();
                    ui.Print(searchAgain);
                    string againInput = ui.GetInput();
                    if (againInput == "1")
                    {
                        continue;
                    }
                    if (againInput == "2")
                    {
                        isSearchOk = false;
                    }
                    break;

                case "2":
                    ui.Print(userString);
                    inputColor = ui.GetInput();
                    ui.Print(searchAgain);
                    againInput = ui.GetInput();
                    if (againInput == "1")
                    {
                        continue;
                    }
                    if (againInput == "2")
                    {
                        isSearchOk = false;
                    }
                    break;

                case "3":
                    ui.Print(userString);
                    inputWheels = Convert.ToInt32(ui.GetInput());
                    ui.Print(searchAgain);
                    againInput = ui.GetInput();
                    if (againInput == "1")
                    {
                        continue;
                    }
                    if (againInput == "2")
                    {
                        isSearchOk = false;
                    }
                    break;

                default:
                    ui.Print("Please enter some valid input (1, 2, 3)");
                    break;
                }
            } while (isSearchOk);

            if (garageHandler.CheckForNull(vList))
            {
                ui.Print("The vehicle was not found!");
            }
            else
            {
                var filter = vList.Where(ve => ve?.Color.ToLower().ToUpper() == inputColor.ToLower().ToUpper() || ve?.NumOfWheels == inputWheels || ve?.GetType().Name.ToUpper().ToLower() == inputType.ToUpper().ToLower());

                foreach (var item in filter)
                {
                    ui.Print($"Found {item.GetType().Name} with color {item.Color} and {item.NumOfWheels} wheels");
                }
            }
        }