コード例 #1
0
        internal static Vehicle createVehicle(eVehicleType i_VehicleType, string i_LicenseNumber)
        {
            Vehicle newVehicle = null;

            switch (i_VehicleType)
            {
            case eVehicleType.FuelMotorCycle:
            {
                newVehicle = new FuelMotorCycle(i_LicenseNumber);
                break;
            }

            case eVehicleType.ElectricMotorCycle:
            {
                newVehicle = new ElectricMotorCycle(i_LicenseNumber);
                break;
            }

            case eVehicleType.FuelCar:
            {
                newVehicle = new FuelCar(i_LicenseNumber);
                break;
            }

            case eVehicleType.ElectricCar:
            {
                newVehicle = new ElectricCar(i_LicenseNumber);
                break;
            }

            case eVehicleType.FuelTruck:
            {
                newVehicle = new FuelTruck(i_LicenseNumber);
                break;
            }
            }

            return(newVehicle);
        }
コード例 #2
0
        public static Vehicle CreateNewVehicle(Garage i_Garage, eVehicleTypes vehicleType, Dictionary <string, string> i_Properties)
        {
            Vehicle      i_Vehicle;
            bool         creationSuccess = false;
            string       modelName = "", licensePlate = "", manufacture = "";
            float        engineCapacity = 0, loadVolume = 0;
            bool         isCarryingDangerousLoad = false;
            eCarDoors    door        = eCarDoors.Five;
            eColor       color       = eColor.Black;
            eLicenseType licenseType = eLicenseType.A;

            foreach (KeyValuePair <string, string> pairs in i_Properties)
            {
                switch (pairs.Key)
                {
                case "Model Name":
                    modelName = pairs.Value;
                    break;

                case "License Plate":
                    licensePlate = pairs.Value;
                    break;

                case "Manufacture":
                    manufacture = pairs.Value;
                    break;

                case "Car Color":
                    eColor.TryParse(pairs.Value, out color);
                    break;

                case "Number of Doors":
                    eCarDoors.TryParse(pairs.Value, out door);
                    break;

                case "Engine Capacity CCS":
                    engineCapacity = float.Parse(pairs.Value);
                    break;

                case "License Type":
                    eLicenseType.TryParse(pairs.Value, out licenseType);
                    break;

                case "Is carrying dangerous load":
                    isCarryingDangerousLoad = bool.Parse(pairs.Value);
                    break;

                case "Load Volume":
                    loadVolume = float.Parse(pairs.Value);
                    break;
                }
            }

            switch (vehicleType)
            {
            case eVehicleTypes.ElectronicCar:
                i_Vehicle = new ElectricCar(modelName, licensePlate, color, door, manufacture);
                //ElectricCar.TryParse(i_Properties, out newVehicle);
                break;

            case eVehicleTypes.ElectronicMotorCycle:
                i_Vehicle = new ElectricMotorCycle(modelName, licensePlate, engineCapacity, eLicenseType.A1, manufacture);
                break;

            case eVehicleTypes.FuelCar:
                i_Vehicle = new FuelCar(modelName, licensePlate, color, door, manufacture);
                //FuelCar.TryParse(i_Properties, out newVehicle);
                break;

            case eVehicleTypes.FuelMotorCycle:
                i_Vehicle = new FuelMotorCycle(modelName, licensePlate, engineCapacity, licenseType, manufacture);
                break;

            case eVehicleTypes.Truck:
                i_Vehicle = new Truck(modelName, licensePlate, manufacture, isCarryingDangerousLoad, loadVolume);
                break;

            default:
                i_Vehicle = null;
                break;
            }
            return(i_Vehicle);
        }