Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var vehicle = new List <Vehicle>();

            for (int i = 0; i < 3; i++)
            {
                vehicle.Add(VehicleFactory.GetVahicle(Console.ReadLine().Split()));
            }
            int commandCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < commandCount; i++)
            {
                try
                {
                    DriveOreRefuel.GetVehicleAtion(Console.ReadLine().Split(), vehicle);
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            foreach (var vehicle1 in vehicle)
            {
                Console.WriteLine(vehicle1);
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            IReader         reader         = new ConsoleReader();
            IWriter         writer         = new ConsoleWriter();
            IVehicleFactory vehicleFactory = new VehicleFactory();
            IEngine         engine         = new Engine(reader, writer, vehicleFactory);

            engine.Run();
        }
Ejemplo n.º 3
0
        public static void Main()
        {
            var vehicles = new Vehicle[3];

            for (int i = 0; i < 3; i++)
            {
                var carInformation = Console.ReadLine();
                vehicles[i] = VehicleFactory.InitializeVehicle(carInformation);
            }

            var commands = int.Parse(Console.ReadLine());

            for (int i = 0; i < commands; i++)
            {
                var commandParts = Console.ReadLine().Split(" ");
                var command      = commandParts[0];
                var vehicleType  = commandParts[1];

                if (command == "Drive")
                {
                    var distance = double.Parse(commandParts[2]);

                    var vehicle = vehicles.FirstOrDefault(x => x.GetType().Name == vehicleType);

                    Console.WriteLine(vehicle?.Drive(distance));
                }
                else if (command == "DriveEmpty")
                {
                    var distance = double.Parse(commandParts[2]);

                    Bus bus = (Bus)vehicles[2];

                    Console.WriteLine(bus.DriveEmpty(distance));
                }
                else if (command == "Refuel")
                {
                    try
                    {
                        var liters = double.Parse(commandParts[2]);

                        var vehicle = vehicles.FirstOrDefault(x => x.GetType().Name == vehicleType);

                        vehicle.Refuel(liters);
                    }
                    catch (ArgumentException ae)
                    {
                        Console.WriteLine(ae.Message);
                    }
                }
            }

            foreach (var vehicle in vehicles)
            {
                Console.WriteLine(vehicle);
            }
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            IReader         reader         = new Reader();
            IWriter         writer         = new Writer();
            IVehicleFactory vehicleFactory = new VehicleFactory();

            Engine engine = new Engine(reader, writer, vehicleFactory);

            engine.Proceed();
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            var carData = Console.ReadLine().Split();
            var car     = VehicleFactory.ProduceVehicle(carData);

            var truckData = Console.ReadLine().Split();
            var truck     = VehicleFactory.ProduceVehicle(truckData);

            var numberOfCommands = int.Parse(Console.ReadLine());

            for (var i = 0; i < numberOfCommands; i++)
            {
                var line = Console.ReadLine().Split();

                var command     = line[0];
                var vehicleType = line[1];
                var value       = double.Parse(line[2]);

                if (command == "Drive")
                {
                    Console.WriteLine(vehicleType == "Car"
                        ? car.Drive(value)
                        : truck.Drive(value));
                }
                else if (command == "Refuel")
                {
                    switch (vehicleType)
                    {
                    case "Car":
                        car.Refuel(value);
                        break;

                    case "Truck":
                        truck.Refuel(value);
                        break;

                    default:
                        break;
                    }
                }
            }

            Console.WriteLine(car.ToString());
            Console.WriteLine(truck.ToString());
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            var car   = VehicleFactory.Manufacture(Console.ReadLine().Split());
            var truck = VehicleFactory.Manufacture(Console.ReadLine().Split());

            var numberOfQueries = int.Parse(Console.ReadLine());

            while (numberOfQueries-- > 0)
            {
                var data = Console.ReadLine().Split();

                var command       = data[0].ToLower();
                var typeOfVehicle = data[1].ToLower();
                var quantityValue = double.Parse(data[2]);

                switch (command)
                {
                case "drive":
                    if (typeOfVehicle == "car")
                    {
                        Console.WriteLine(car.DriveVehicle(quantityValue));
                    }
                    else if (typeOfVehicle == "truck")
                    {
                        Console.WriteLine(truck.DriveVehicle(quantityValue));
                    }
                    break;

                case "refuel":
                    if (typeOfVehicle == "car")
                    {
                        car.RefuelVehicle(quantityValue);
                    }
                    else if (typeOfVehicle == "truck")
                    {
                        truck.RefuelVehicle(quantityValue);
                    }
                    break;
                }
            }

            Console.WriteLine(car + Environment.NewLine + truck);
        }
Ejemplo n.º 7
0
        static void Main()
        {
            Car   car              = (Car)VehicleFactory.CreateVehicle();
            Truck truck            = (Truck)VehicleFactory.CreateVehicle();
            Bus   bus              = (Bus)VehicleFactory.CreateVehicle();
            int   numberOfCommands = int.Parse(Console.ReadLine());

            for (int i = 0; i < numberOfCommands; i++)
            {
                string[] commands    = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   action      = commands[0];
                string   vehicleType = commands[1];
                double   argument    = double.Parse(commands[2]);

                ExecuteAction(car, truck, bus, action, vehicleType, argument);
            }
            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            DataProcessor Data         = new DataProcessor();
            string        FileLocation = @"C: \Users\AminR\source\repos\Vehicles\Persons.txt";

            string[]       TextFileInputs = Data.GetDataFromTextFile(FileLocation);
            List <Vehicle> VehicleList    = new List <Vehicle>();
            bool           Driving        = true;


            foreach (string TextFileInput in TextFileInputs)
            {
                VehicleFactory vehicles = new VehicleFactory();
                int            Seats    = Convert.ToInt32(Data.ExtractNumberFromString(TextFileInput));
                VehicleList.Add(vehicles.CreateVehicle(Seats));
            }

            while (Driving)
            {
                Data.VehicleFuelUsage(VehicleList);
            }
            Console.ReadKey();
        }
Ejemplo n.º 9
0
 private Engine()
 {
     vehicleFactory = new VehicleFactory();
 }
Ejemplo n.º 10
0
        public static void Main()
        {
            string[] carInfo = Console.ReadLine().Split(" ");
            var      car     = VehicleFactory.Create(carInfo);

            string[] truckInfo = Console.ReadLine().Split(" ");
            var      truck     = VehicleFactory.Create(truckInfo);

            string[] busInfo = Console.ReadLine().Split(" ");
            var      bus     = VehicleFactory.Create(busInfo);

            int commandsCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < commandsCount; i++)
            {
                string[] userCommandProps = Console.ReadLine().Split(" ");

                string command     = userCommandProps[0];
                string vehicleType = userCommandProps[1];

                try
                {
                    if (vehicleType == "Car")
                    {
                        if (command == "Refuel")
                        {
                            double fuel = double.Parse(userCommandProps[2]);
                            car.Refuel(fuel);
                        }
                        else if (command == "Drive")
                        {
                            double distance = double.Parse(userCommandProps[2]);
                            Console.WriteLine(car.Drive(distance));
                        }
                    }
                    else if (vehicleType == "Truck")
                    {
                        if (command == "Refuel")
                        {
                            double fuel = double.Parse(userCommandProps[2]);
                            truck.Refuel(fuel);
                        }
                        else if (command == "Drive")
                        {
                            double distance = double.Parse(userCommandProps[2]);
                            Console.WriteLine(truck.Drive(distance));
                        }
                    }
                    else if (vehicleType == "Bus")
                    {
                        if (command == "Refuel")
                        {
                            double fuel = double.Parse(userCommandProps[2]);
                            bus.Refuel(fuel);
                        }
                        else if (command == "Drive")
                        {
                            double distance = double.Parse(userCommandProps[2]);
                            Console.WriteLine(bus.Drive(distance));
                        }
                        else if (command == "DriveEmpty")
                        {
                            double distance = double.Parse(userCommandProps[2]);
                            Console.WriteLine(bus.DriveEmpty(distance));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.WriteLine(car.ToString());
            Console.WriteLine(truck.ToString());
            Console.WriteLine(bus.ToString());
        }