コード例 #1
0
        public static Vehicle CreateVehicle(Vehicle.eVehicleTypes i_VehicleType, string i_Model, string i_LicenseNumber, float i_EnergyLeft, List <Wheel> i_Wheels, Engine i_engine, Dictionary <string, object> features)
        {
            Vehicle vehicle = null;

            switch (i_VehicleType)
            {
            case Vehicle.eVehicleTypes.ElectricCar:
                vehicle = new ElectricCar((Vehicle.eCarColors)features["i_CarColor"], (Vehicle.eCarDoorsAmount)features["i_CarDoors"]);
                break;

            case Vehicle.eVehicleTypes.GasCar:
                vehicle = new GasCar((Vehicle.eCarColors)features["i_CarColor"], (Vehicle.eCarDoorsAmount)features["i_CarDoors"]);
                break;

            case Vehicle.eVehicleTypes.ElectricMotorcycle:
                vehicle = new ElectricMotorcycle((Vehicle.eLicenseTypes)features["i_MotorcycleLicenseType"], (int)features["i_EngineCapacity"]);
                break;

            case Vehicle.eVehicleTypes.GasMotorcycle:
                vehicle = new GasMotorcycle((Vehicle.eLicenseTypes)features["i_MotorcycleLicenseType"], (int)features["i_EngineCapacity"]);
                break;

            case Vehicle.eVehicleTypes.Truck:
                vehicle = new Truck((bool)features["i_IsCarryingDangerousMaterials"], (float)features["i_MaximumCarryingWeight"]);
                break;
            }

            vehicle.m_EnergyLeft  = i_EnergyLeft;
            vehicle.Engine        = i_engine;
            vehicle.Wheels        = i_Wheels;
            vehicle.LicenseNumber = i_LicenseNumber;
            vehicle.m_Model       = i_Model;
            return(vehicle);
        }
コード例 #2
0
        public static Engine CreateEngine(Vehicle.eVehicleTypes i_VehicleType, float i_EnergyLevel)
        {
            Engine engine = null;

            switch (i_VehicleType)
            {
            case Vehicle.eVehicleTypes.GasMotorcycle:
                engine = new GasEngine(Vehicle.eGasTypes.Octan95, i_EnergyLevel, 5.5f);
                break;

            case Vehicle.eVehicleTypes.ElectricMotorcycle:
                engine = new ElectricEngine(i_EnergyLevel, 2.7f);
                break;

            case Vehicle.eVehicleTypes.GasCar:
                engine = new GasEngine(Vehicle.eGasTypes.Octan98, i_EnergyLevel, 42.0f);
                break;

            case Vehicle.eVehicleTypes.ElectricCar:
                engine = new ElectricEngine(i_EnergyLevel, 2.5f);
                break;

            case Vehicle.eVehicleTypes.Truck:
                engine = new GasEngine(Vehicle.eGasTypes.Octan96, i_EnergyLevel, 135.0f);
                break;
            }

            return(engine);
        }
コード例 #3
0
        public static List <Wheel> NewWheels(Vehicle.eVehicleTypes i_VehicleType, string i_ManufacturerName, float i_CurrentAirPressure)
        {
            List <Wheel> wheels             = new List <Wheel>();
            int          numberOfWheels     = 0;
            float        maximumAirPressure = 0;

            switch (i_VehicleType)
            {
            case Vehicle.eVehicleTypes.GasMotorcycle:
            case Vehicle.eVehicleTypes.ElectricMotorcycle:
                numberOfWheels     = 2;
                maximumAirPressure = 33.0f;
                break;

            case Vehicle.eVehicleTypes.GasCar:
            case Vehicle.eVehicleTypes.ElectricCar:
                numberOfWheels     = 4;
                maximumAirPressure = 30.0f;
                break;

            case Vehicle.eVehicleTypes.Truck:
                numberOfWheels     = 12;
                maximumAirPressure = 32.0f;
                break;
            }

            if (maximumAirPressure < i_CurrentAirPressure || i_CurrentAirPressure < 0)
            {
                throw new ArgumentException(string.Format("Wheel's air pressure must be between {0} to {1}", 0, maximumAirPressure));
            }

            for (int i = 0; i < numberOfWheels; i++)
            {
                wheels.Add(new Wheel(i_ManufacturerName, i_CurrentAirPressure, maximumAirPressure));
            }

            return(wheels);
        }
コード例 #4
0
        private void insertNewVehicleToGarage(string i_LicenseNumber)
        {
            string ownerName        = this.inputFromUser("Enter owner's name:");
            string ownerPhoneNumber = this.PhoneNumberFromUser();
            string modelName        = string.Empty;
            string wheelProducer    = string.Empty;
            float  energyLevel      = 0;
            float  wheelAirPressure = 0;
            int    engineCapacity   = 0;

            Vehicle.eCarColors      color;
            Vehicle.eCarDoorsAmount door;
            Vehicle.eLicenseTypes   LicenseType;
            Engine       engine  = null;
            List <Wheel> wheels  = null;
            Vehicle      vehicle = null;
            Dictionary <string, object> features = new Dictionary <string, object>();

            Console.WriteLine();
            string vehicleTypeMsg = string.Format(
                @"Choose vehicle type:
1) Gas car.
2) Electric car.
3) Gas motorcycle.
4) Electric motorcycle.
5) Truck.");

            Console.WriteLine(vehicleTypeMsg);
            Vehicle.eVehicleTypes vehicleType = (Vehicle.eVehicleTypes)inputFromUserAndCheckIfInRangeInt(1, 5);
            modelName     = inputFromUser("Insert the " + vehicleType + " Model name:");
            wheelProducer = inputFromUser("Insert wheels producer:");
            switch (vehicleType)
            {
            case Vehicle.eVehicleTypes.GasCar:
                Console.WriteLine("Insert current fuel level:");
                energyLevel = inputFromUserAndCheckIfInRangeFloat(0, 42.0f);
                Console.WriteLine("Insert current wheel air pressure:");
                wheelAirPressure = inputFromUserAndCheckIfInRangeFloat(0, 30.0f);
                color            = (Vehicle.eCarColors)inputCarColor();
                features.Add("i_CarColor", color);
                door = (Vehicle.eCarDoorsAmount)inputNumberOfCarDoors();
                features.Add("i_CarDoors", door);
                break;

            case Vehicle.eVehicleTypes.ElectricCar:
                Console.WriteLine("Insert current battery level:");
                energyLevel = inputFromUserAndCheckIfInRangeFloat(0, 2.5f);
                Console.WriteLine("Insert current wheel air Pressure:");
                wheelAirPressure = inputFromUserAndCheckIfInRangeFloat(0, 30.0f);
                color            = (Vehicle.eCarColors)inputCarColor();
                features.Add("i_CarColor", color);
                door = (Vehicle.eCarDoorsAmount)inputNumberOfCarDoors();
                features.Add("i_CarDoors", door);
                break;

            case Vehicle.eVehicleTypes.GasMotorcycle:
                Console.WriteLine("Insert current fuel level:");
                energyLevel = inputFromUserAndCheckIfInRangeFloat(0, 5.5f);
                Console.WriteLine("Insert wheel air pressure:");
                wheelAirPressure = inputFromUserAndCheckIfInRangeFloat(0, 33.0f);
                LicenseType      = (Vehicle.eLicenseTypes)inputMotorcycleLicenseType();
                features.Add("i_MotorcycleLicenseType", LicenseType);
                Console.WriteLine("Insert engine capacity:");
                engineCapacity = inputFromUserAndCheckIfInRangeInt(0, 3000);
                features.Add("i_EngineCapacity", engineCapacity);
                break;

            case Vehicle.eVehicleTypes.ElectricMotorcycle:
                Console.WriteLine("Insert current battery level:");
                energyLevel = inputFromUserAndCheckIfInRangeFloat(0, 2.7f);
                Console.WriteLine("Insert current wheel air pressure:");
                wheelAirPressure = inputFromUserAndCheckIfInRangeFloat(0, 33.0f);
                LicenseType      = (Vehicle.eLicenseTypes)inputMotorcycleLicenseType();
                features.Add("i_MotorcycleLicenseType", LicenseType);
                Console.WriteLine("Insert engine capacity:");
                engineCapacity = inputFromUserAndCheckIfInRangeInt(0, 3000);
                features.Add("i_EngineCapacity", engineCapacity);
                break;

            case Vehicle.eVehicleTypes.Truck:
                Console.WriteLine("Insert current fuel level:");
                energyLevel = inputFromUserAndCheckIfInRangeFloat(0, 135.0f);
                Console.WriteLine("Insert current wheel air pressure:");
                wheelAirPressure = inputFromUserAndCheckIfInRangeFloat(0, 32.0f);
                string chooseIfCarryingDangerousMaterials = string.Format(
                    @"Choose if the truck is carrying dangerous materials:
1) Yes.
2) No.");
                Console.WriteLine(chooseIfCarryingDangerousMaterials);
                bool isCarryingDangerousMaterials = inputFromUserAndCheckIfInRangeInt(1, 2) == 1;
                features.Add("i_IsCarryingDangerousMaterials", isCarryingDangerousMaterials);
                Console.WriteLine("Insert maximum carrying Weight:");
                float maxCarryingWeight = inputFromUserAndCheckIfInRangeFloat(0, 60000);
                features.Add("i_MaximumCarryingWeight", maxCarryingWeight);
                break;
            }

            engine = CreateNewVehicle.CreateEngine(vehicleType, energyLevel);
            wheels = CreateNewVehicle.NewWheels(vehicleType, wheelProducer, wheelAirPressure);
            try
            {
                vehicle = CreateNewVehicle.CreateVehicle(vehicleType, modelName, i_LicenseNumber, energyLevel, wheels, engine, features);
                m_Garage.InsertVehicleToTheGarage(ownerName, ownerPhoneNumber, vehicle);
                Console.WriteLine("New vehicle was added succesfully!");
            }
            catch
            {
                Console.WriteLine("There was a problem while trying to insert the vehicle to the garage, please try again!");
            }
        }