Exemplo n.º 1
0
        private Vehicle chooseVehicleType(string i_LicenseNumber)
        {
            // The next printing section was done with Enum.GetName because of note number 4 in the document exercise.
            // In this way, the system can add new vehicles with adding the new vehicle class and editing the "CreateVehicle.cs" code only.
            Vehicle newVehicle = null;

            Console.WriteLine("Select vehicle type:");
            string[] supportedVehicleTypes = Enum.GetNames(typeof(VehicleCreator.eSupportedVehicles));
            for (int i = 1; i <= supportedVehicleTypes.Length; i++)
            {
                Console.WriteLine("{0}. {1}", i, supportedVehicleTypes[i - 1]);
            }

            int  vehicleTypeChoice;
            bool isValidSelection = false;

            while (isValidSelection == false)
            {
                vehicleTypeChoice = readIntFromConsole();
                try
                {
                    newVehicle       = VehicleCreator.MakeVehicle(vehicleTypeChoice, i_LicenseNumber);
                    isValidSelection = true;
                }
                catch (ArgumentException)
                {
                    UIMessages.DisplayMessages(UIMessages.eGeneralMessages.InvalidSelection);
                }
            }

            return(newVehicle);
        }
Exemplo n.º 2
0
        private string readNonEmptyStringFromConsole()
        {
            string userInput = Console.ReadLine();

            while (userInput.Length == 0)
            {
                UIMessages.DisplayMessages(UIMessages.eGeneralMessages.InvalidInput);
                userInput = Console.ReadLine();
            }

            return(userInput);
        }
Exemplo n.º 3
0
        private float readFloatFromConsole()
        {
            float  parsedNumber;
            string userInput = Console.ReadLine();

            while (!float.TryParse(userInput, out parsedNumber))
            {
                UIMessages.DisplayMessages(UIMessages.eGeneralMessages.InvalidInput);
                userInput = Console.ReadLine();
            }

            return(parsedNumber);
        }
Exemplo n.º 4
0
        private void printMainMenu()
        {
            UIMessages.DisplayMessages(UIMessages.eGeneralMessages.Seperator);
            UIMessages.DisplayMessages(UIMessages.eGeneralMessages.MainMenu);
            UIMessages.DisplayMessages(UIMessages.eGeneralMessages.Seperator);
            for (int row = 1; row <= 12; row++)
            {
                Console.SetCursorPosition(49, row);
                Console.Write('|');
            }

            Console.SetCursorPosition(0, 14);
        }
Exemplo n.º 5
0
        private void preformOperations(int i_OperationChoice)
        {
            bool isOperationSuccessful = false;

            switch ((eGarageOperations)i_OperationChoice)
            {
            case eGarageOperations.AddNewVehicleToGarage:
                isOperationSuccessful = addNewVehicleToGarage();
                break;

            case eGarageOperations.DisplayLicenseNumbers:
                displayLicenseNumbers();
                break;

            case eGarageOperations.ChangeVehicleStatus:
                isOperationSuccessful = changeVehicleStatus();
                break;

            case eGarageOperations.InflateWheels:
                isOperationSuccessful = inflateWheels();
                break;

            case eGarageOperations.FuelAVehicle:
                isOperationSuccessful = fuelAVehicle();
                break;

            case eGarageOperations.ChargeAVehicle:
                isOperationSuccessful = chargeAVehicle();
                break;

            case eGarageOperations.DisplayVehicleData:
                displayVehicleData();
                break;

            case eGarageOperations.Exit:
                m_SystemStatus = eSystemStatus.Off;
                break;

            default:
                throw new ArgumentException();
            }

            UIMessages.DisplayMessages(UIMessages.eGeneralMessages.Seperator);
            if (isOperationSuccessful)
            {
                UIMessages.DisplayMessages(UIMessages.eGeneralMessages.OperationSuccess);
            }

            UIMessages.DisplayMessages(UIMessages.eGeneralMessages.PressAnyKeyToContinue);
        }
Exemplo n.º 6
0
        private void makeGarageOperations()
        {
            bool isValidChoice = false;

            while (isValidChoice == false)
            {
                int operation = readIntFromConsole();
                try
                {
                    preformOperations(operation);
                    isValidChoice = true;
                }
                catch (ArgumentException)
                {
                    UIMessages.DisplayMessages(UIMessages.eGeneralMessages.InvalidSelection);
                }
            }
        }
Exemplo n.º 7
0
        private void displayLicenseNumbers()
        {
            bool isOperationDone = false;

            Console.WriteLine(@"Choose one of the following options:
1. Dispaly license with status Repair.
2. Dispaly license with status Repaired.
3. Dispaly license with status Paid.
4. Display all license numbers.");
            while (isOperationDone == false)
            {
                int selectedOptionFromUser = readIntFromConsole();
                try
                {
                    switch ((OwnerInfo.eVehicleSatuses)selectedOptionFromUser)
                    {
                    case OwnerInfo.eVehicleSatuses.Repair:
                        Console.WriteLine(r_GarageManager.DisplayVehicleLicenseNumbers(false, (OwnerInfo.eVehicleSatuses)selectedOptionFromUser));
                        isOperationDone = true;
                        break;

                    case OwnerInfo.eVehicleSatuses.Repaired:
                        Console.WriteLine(r_GarageManager.DisplayVehicleLicenseNumbers(false, (OwnerInfo.eVehicleSatuses)selectedOptionFromUser));
                        isOperationDone = true;
                        break;

                    case OwnerInfo.eVehicleSatuses.Paid:
                        Console.WriteLine(r_GarageManager.DisplayVehicleLicenseNumbers(false, (OwnerInfo.eVehicleSatuses)selectedOptionFromUser));
                        isOperationDone = true;
                        break;

                    default:
                        Console.WriteLine(r_GarageManager.DisplayVehicleLicenseNumbers(true, (OwnerInfo.eVehicleSatuses)selectedOptionFromUser));
                        isOperationDone = true;
                        break;
                    }
                }
                catch (ArgumentException)
                {
                    UIMessages.DisplayMessages(UIMessages.eGeneralMessages.InvalidSelection);
                }
            }
        }
Exemplo n.º 8
0
        private void getUniqueVehicleAttributes(Vehicle i_Vehicle)
        {
            // Th is method use reflection using MethodInfo. this is for note number 4 in the document exercise.
            // The reflection help to get the unique memebers of each different vehicle without hard coding for a specific type in the UI.
            // In this way, the system can add new vehicles with adding the new vehicle class and editing the "CreateVehicle.cs" code only.
            List <List <string> > uniqueAttributes = i_Vehicle.UniqueAttributes(); // create list of List<string> with 2 values, in number [0] there is the output messeage. in number [1] there is the method name

            foreach (List <string> attribute in uniqueAttributes)
            {
                bool validInput = false;
                Console.WriteLine(attribute[0]); // in attribute[0] there is the current unique method relevant message to output
                while (validInput == false)
                {
                    MethodInfo uniqueMethod = i_Vehicle.GetType().GetMethod(attribute[1]); // in attribute[1] there is the name of the current unique vehicle method to use
                    try
                    {
                        string currentAttributeInput = Console.ReadLine();                                   // get input data from user
                        invokeUniqueMethod(uniqueMethod, i_Vehicle, new object[] { currentAttributeInput }); // call to the current unique method
                        validInput = true;
                    }
                    catch (FormatException)
                    {   // handle parsing exceptions
                        UIMessages.DisplayMessages(UIMessages.eGeneralMessages.InvalidInput);
                    }
                    catch (ArgumentException)
                    {   // handle bad choice exception
                        UIMessages.DisplayMessages(UIMessages.eGeneralMessages.InvalidSelection);
                    }
                    catch (ValueOutOfRangeException voore)
                    {   // handle out of range exception
                        Console.WriteLine(voore.ToString());
                    }
                    catch (Exception e)
                    {
                        // handle any other exceptions
                        Console.WriteLine(e.Message);
                    }
                }
            }
        }
Exemplo n.º 9
0
        private bool changeVehicleStatus()
        {
            bool   isVehicleExists = false;
            string licenseNumber   = getLicenseNumber();

            isVehicleExists = r_GarageManager.IsVehicleExists(licenseNumber);
            if (isVehicleExists == true)
            {
                string[] vehicleStatuses = Enum.GetNames(typeof(OwnerInfo.eVehicleSatuses));
                Console.WriteLine("Select new status:");
                for (int i = 1; i <= vehicleStatuses.Length; i++)
                {
                    Console.WriteLine("{0}. {1}", i, vehicleStatuses[i - 1]);
                }

                bool isValidSelection = false;
                while (isValidSelection == false)
                {
                    int newStatus = readIntFromConsole();
                    try
                    {
                        r_GarageManager.ChangeVehicleStatus(licenseNumber, (OwnerInfo.eVehicleSatuses)newStatus);
                        isValidSelection = true;
                    }
                    catch (ArgumentException)
                    {
                        UIMessages.DisplayMessages(UIMessages.eGeneralMessages.InvalidSelection);
                    }
                }
            }
            else
            {
                Console.WriteLine("Vehicle does not exist in the garage.");
            }

            return(isVehicleExists);
        }