Exemplo n.º 1
0
        public static void PrintAllVehicleInTheGarage(Garage i_MyGarage, string i_UserChoiceOfAction)
        {
            string outputMessage = null;
            int    counter       = 0;

            if (i_UserChoiceOfAction == "2")
            {
                Console.WriteLine("All the vehicles' license number in the garage are:");

                foreach (KeyValuePair <string, GarageSlot> currentEntryInTheDictionary in i_MyGarage.M_MyGarage)
                {
                    outputMessage = string.Format("{0}.{1}", counter + 1, currentEntryInTheDictionary.Value.M_Vehicle.M_LicenseNumber);
                    Console.WriteLine(outputMessage);
                    counter += 1;
                }
            }
            else
            {
                bool                     enterLoop = true;
                List <string>            listOfVehiclesFilterdByStatus;
                GarageSlot.eGarageStatus userChoiceOfVehicleCondition = GarageSlot.eGarageStatus.BeingFixed; ///temporary.

                while (enterLoop)
                {
                    try
                    {
                        Console.WriteLine("Please enter the condition of the vehicles in the garage that you'd like to see out of the following options by choosing a number:\n1.Being Fixed\n2.Ready\n3.Paid For");
                        userChoiceOfVehicleCondition = GarageSlot.ToEGarageStatus(Console.ReadLine());
                        enterLoop = false;
                    }
                    catch (FormatException exception)
                    {
                        Console.WriteLine(exception.Message);
                    }
                }

                listOfVehiclesFilterdByStatus = i_MyGarage.CreateListByVehicleStatus(userChoiceOfVehicleCondition);
                if (listOfVehiclesFilterdByStatus.Count > 0)
                {
                    Console.WriteLine(string.Format("The vehicles in the garage that are {0} are:", userChoiceOfVehicleCondition.ToString()));

                    foreach (string currentVehicleLicenseNumber in listOfVehiclesFilterdByStatus)
                    {
                        outputMessage = string.Format("{0}.{1}", counter + 1, currentVehicleLicenseNumber);
                        Console.WriteLine(outputMessage);
                        counter += 1;
                    }
                }
                else
                {
                    throw new Exception("There are no vehicles in the garage with the chosen condition!");
                }
            }
        }
Exemplo n.º 2
0
        public List <string> CreateListByVehicleStatus(GarageSlot.eGarageStatus i_FilterStatus)
        {
            List <string> o_FilteredVehicles = new List <string>();

            foreach (KeyValuePair <string, GarageSlot> garageSlot in m_MyGarage)
            {
                if (garageSlot.Value.M_CurrentStatus == i_FilterStatus)
                {
                    o_FilteredVehicles.Add(garageSlot.Value.M_Vehicle.M_LicenseNumber);
                }
            }

            return(o_FilteredVehicles);
        }
Exemplo n.º 3
0
        public static void ChangeVehicleStatus(Garage io_MyGarage)
        {
            bool   enterLoop          = true;
            string ownerLicenseNumber = null;

            GarageSlot.eGarageStatus newVehicleStatus = GarageSlot.eGarageStatus.BeingFixed;
            GarageSlot currentGarageSlot = null;

            Console.WriteLine("Please enter the vehicle license number");
            ownerLicenseNumber = Console.ReadLine();

            if (io_MyGarage.M_MyGarage.TryGetValue(ownerLicenseNumber, out currentGarageSlot) == false)
            {
                throw new ArgumentException("The vehicle with license number you entered does not exist in the garage ! ! !");
            }
            else
            {
                Console.WriteLine("Choose one of the following vehicle's statuses:\n1.Being Fixed\n2.Ready\n3.Paid For");

                while (enterLoop == true)
                {
                    try
                    {
                        newVehicleStatus = GarageSlot.ToEGarageStatus(Console.ReadLine());
                        currentGarageSlot.UpdateVehicleStatus(newVehicleStatus);
                        enterLoop = false;
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception.Message);
                    }
                }

                Console.WriteLine(string.Format("Success, vehicle license number {0} condition was updated to {1}.\n", ownerLicenseNumber, newVehicleStatus.ToString()));
            }
        }