예제 #1
0
파일: Engine.cs 프로젝트: vesy53/SoftUni
        public void Run()
        {
            int radius = int.Parse(reader.ConsoleReadLine());
            int width  = int.Parse(reader.ConsoleReadLine());
            int height = int.Parse(reader.ConsoleReadLine());

            IDrawable circle = new Circle(radius);
            IDrawable rect   = new Rectangle(width, height);

            circle.Draw();
            rect.Draw();
        }
예제 #2
0
        public void Run()
        {
            string input = reader.ConsoleReadLine();

            while (input.Equals("End") == false)
            {
                string[] tokens = input
                                  .Split(" ",
                                         StringSplitOptions
                                         .RemoveEmptyEntries);

                string name    = tokens[0];
                string country = tokens[1];
                int    age     = int.Parse(tokens[2]);

                Citizen citizen = new Citizen(
                    name,
                    country,
                    age);

                IPerson   person   = citizen;
                IResident resident = citizen;

                person.GetName();
                resident.GetName();

                input = Console.ReadLine();
            }
        }
예제 #3
0
파일: Engine.cs 프로젝트: vesy53/SoftUni
        public void Run()
        {
            try
            {
                double length = double.Parse(reader.ConsoleReadLine());
                double width  = double.Parse(reader.ConsoleReadLine());
                double height = double.Parse(reader.ConsoleReadLine());

                Box box = new Box(length, width, height);

                writer.ConsoleWriteLine(box.ToString());
            }
            catch (Exception ex)
            {
                writer.ConsoleWriteLine(ex.Message);
            }
        }
예제 #4
0
파일: Engine.cs 프로젝트: vesy53/SoftUni
        public void Run()
        {
            try
            {
                string[] pizzaInput = reader
                                      .ConsoleReadLine()
                                      .Split(" ");
                string[] doughInput = reader
                                      .ConsoleReadLine()
                                      .Split(" ");

                string pizzaName = pizzaInput[1];

                string flour         = doughInput[1];
                string baking        = doughInput[2];
                double weightInGrams = double.Parse(doughInput[3]);

                Dough dough = new Dough(flour, baking, weightInGrams);

                Pizza pizza = new Pizza(pizzaName, dough);

                string input = reader.ConsoleReadLine();

                while (input.Equals("END") == false)
                {
                    string[] toppingArgs = input
                                           .Split(" ");

                    string type   = toppingArgs[1];
                    double weight = double.Parse(toppingArgs[2]);

                    Topping topping = new Topping(type, weight);

                    pizza.AddTopping(topping);

                    input = reader.ConsoleReadLine();
                }

                writer.ConsoleWriteLine(pizza.ToString());
            }
            catch (ArgumentException ae)
            {
                Console.WriteLine(ae.Message);
            }
        }
예제 #5
0
파일: Engine.cs 프로젝트: vesy53/SoftUni
        public void Run()
        {
            List <Team> teams = new List <Team>();

            string input = reader.ConsoleReadLine();

            while (input.Equals("END") == false)
            {
                try
                {
                    string[] tokens = input
                                      .Split(';');

                    string command = tokens[0].ToLower();

                    if (command == "team")
                    {
                        string teamName = tokens[1];

                        Team team = new Team(teamName);

                        teams.Add(team);
                    }
                    else if (command == "add")
                    {
                        AddPlayerToTheTeam(teams, tokens);
                    }
                    else if (command == "remove")
                    {
                        RemovePlayerFromTheTeam(teams, tokens);
                    }
                    else if (command == "rating")
                    {
                        PrintTheTeamReating(teams, tokens);
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }

                input = reader.ConsoleReadLine();
            }
        }
예제 #6
0
파일: Engine.cs 프로젝트: vesy53/SoftUni
        public void Run()
        {
            string[] inputCar = reader
                                .ConsoleReadLine()
                                .Split(" ",
                                       StringSplitOptions
                                       .RemoveEmptyEntries);
            string[] inputTruck = reader
                                  .ConsoleReadLine()
                                  .Split(" ",
                                         StringSplitOptions
                                         .RemoveEmptyEntries);

            double carFuelQuantity = double.Parse(inputCar[1]);
            double carLiters       = double.Parse(inputCar[2]);

            double truckFuelQuantity = double.Parse(inputTruck[1]);
            double truckLiters       = double.Parse(inputTruck[2]);

            IVehicle car   = new Car(carFuelQuantity, carLiters);
            IVehicle truck = new Truck(truckFuelQuantity, truckLiters);

            int number = int.Parse(reader.ConsoleReadLine());

            for (int i = 0; i < number; i++)
            {
                string[] tokens = reader
                                  .ConsoleReadLine()
                                  .Split(" ",
                                         StringSplitOptions
                                         .RemoveEmptyEntries);

                string command     = tokens[0];
                string typeVehicle = tokens[1];

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

                    string result = string.Empty;

                    if (typeVehicle == "Car")
                    {
                        result = car.Drive(distance);
                    }
                    else if (typeVehicle == "Truck")
                    {
                        result = truck.Drive(distance);
                    }

                    Console.WriteLine(result);
                }
                else if (command == "Refuel")
                {
                    double amountFuel = double.Parse(tokens[2]);

                    if (typeVehicle == "Car")
                    {
                        car.Refuel(amountFuel);
                    }
                    else if (typeVehicle == "Truck")
                    {
                        truck.Refuel(amountFuel);
                    }
                }
            }

            writer.ConsoleWriteLine(car.ToString());
            writer.ConsoleWriteLine(truck.ToString());
        }
예제 #7
0
파일: Engine.cs 프로젝트: vesy53/SoftUni
        public void Run()
        {
            string[] inputCar = reader
                                .ConsoleReadLine()
                                .Split(" ",
                                       StringSplitOptions
                                       .RemoveEmptyEntries);
            string[] inputTruck = reader
                                  .ConsoleReadLine()
                                  .Split(" ",
                                         StringSplitOptions
                                         .RemoveEmptyEntries);
            string[] inputBus = reader
                                .ConsoleReadLine()
                                .Split(" ",
                                       StringSplitOptions
                                       .RemoveEmptyEntries);

            double carFuelQuantity = double.Parse(inputCar[1]);
            double carLiters       = double.Parse(inputCar[2]);
            double carTankCapacity = double.Parse(inputCar[3]);

            double truckFuelQuantity = double.Parse(inputTruck[1]);
            double truckLiters       = double.Parse(inputTruck[2]);
            double truckTankCapacity = double.Parse(inputTruck[3]);

            double busFuelQuantity = double.Parse(inputBus[1]);
            double busLiters       = double.Parse(inputBus[2]);
            double busTankCapacity = double.Parse(inputBus[3]);

            IVehicle car   = new Car(carFuelQuantity, carLiters, carTankCapacity);
            IVehicle truck = new Truck(truckFuelQuantity, truckLiters, truckTankCapacity);
            Bus      bus   = new Bus(busFuelQuantity, busLiters, busTankCapacity);

            int number = int.Parse(reader.ConsoleReadLine());

            for (int i = 0; i < number; i++)
            {
                try
                {
                    string[] tokens = reader
                                      .ConsoleReadLine()
                                      .Split(" ",
                                             StringSplitOptions
                                             .RemoveEmptyEntries);

                    string command     = tokens[0];
                    string typeVehicle = tokens[1];

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

                        string result = string.Empty;

                        if (typeVehicle == "Car")
                        {
                            result = car.Drive(distance);
                        }
                        else if (typeVehicle == "Truck")
                        {
                            result = truck.Drive(distance);
                        }
                        else if (typeVehicle == "Bus")
                        {
                            result = bus.Drive(distance);
                        }

                        writer.ConsoleWriteLine(result);
                    }
                    else if (command == "Refuel")
                    {
                        double amountFuel = double.Parse(tokens[2]);

                        if (typeVehicle == "Car")
                        {
                            car.Refuel(amountFuel);
                        }
                        else if (typeVehicle == "Truck")
                        {
                            truck.Refuel(amountFuel);
                        }
                        else if (typeVehicle == "Bus")
                        {
                            bus.Refuel(amountFuel);
                        }
                    }
                    else if (command == "DriveEmpty" &&
                             typeVehicle == "Bus")
                    {
                        double distance = double.Parse(tokens[2]);

                        string result = bus.DriveEmpty(distance);

                        writer.ConsoleWriteLine(result);
                    }
                }
                catch (ArgumentException ae)
                {
                    writer.ConsoleWriteLine(ae.Message);
                }
            }

            writer.ConsoleWriteLine(car.ToString());
            writer.ConsoleWriteLine(truck.ToString());
            writer.ConsoleWriteLine(bus.ToString());
        }
예제 #8
0
        public void Run()
        {
            string input = reader.ConsoleReadLine();

            while (input.Equals("End") == false)
            {
                string[] tokens = input
                                  .Split(" ",
                                         StringSplitOptions
                                         .RemoveEmptyEntries);

                string  type      = tokens[0];
                int     id        = int.Parse(tokens[1]);
                string  firstName = tokens[2];
                string  lastName  = tokens[3];
                decimal salary    = decimal.Parse(tokens[4]);

                if (type == "Private")
                {
                    Private soldier = new Private(id, firstName, lastName, salary);

                    this.soldiers.Add(soldier);
                }
                else if (type == "LieutenantGeneral")
                {
                    LieutenantGeneral general = new LieutenantGeneral(id, firstName, lastName, salary);

                    for (int i = 5; i < tokens.Length; i++)
                    {
                        int privateId = int.Parse(tokens[i]);

                        IPrivate privateSoldier = (IPrivate)this.soldiers
                                                  .FirstOrDefault(x => x.Id == privateId);

                        general.AddPrivate(privateSoldier);
                    }

                    this.soldiers.Add(general);
                }
                else if (type == "Engineer")
                {
                    try
                    {
                        string corps = tokens[5];

                        IEngineer engineer = new Engineer(id, firstName, lastName, salary, corps);

                        for (int i = 6; i < tokens.Length; i += 2)
                        {
                            string partName    = tokens[i];
                            int    workedHours = int.Parse(tokens[i + 1]);

                            IRepair repair = new Repair(partName, workedHours);

                            engineer.AddRepair(repair);
                        }

                        this.soldiers.Add(engineer);
                    }
                    catch (ArgumentException ae)
                    {
                    }
                }
                else if (type == "Commando")
                {
                    try
                    {
                        string corps = tokens[5];

                        ICommando commando = new Commando(id, firstName, lastName, salary, corps);

                        for (int i = 6; i < tokens.Length; i += 2)
                        {
                            try
                            {
                                string codeName = tokens[i];
                                string state    = tokens[i + 1];

                                IMission mission = new Mission(codeName, state);

                                commando.AddMission(mission);
                            }
                            catch (ArgumentException ae)
                            {
                                continue;
                            }
                        }

                        this.soldiers.Add(commando);
                    }
                    catch (ArgumentException ae)
                    {
                    }
                }
                else if (type == "Spy")
                {
                    int codeNumber = (int)salary;

                    ISpy spy = new Spy(id, firstName, lastName, codeNumber);

                    this.soldiers.Add(spy);
                }

                input = Console.ReadLine();
            }

            foreach (ISoldier soldier in soldiers)
            {
                writer.ConsoleWriteLine(soldier);
            }
        }