Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            List <Car>    cars        = new List <Car>();
            List <Engine> engines     = new List <Engine>();
            int           engineCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < engineCount; i++)
            {
                string[] parameters = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   model      = parameters[0];
                int      power      = int.Parse(parameters[1]);

                int displacement = -1;

                if (parameters.Length == 3 && int.TryParse(parameters[2], out displacement))
                {
                    engines.Add(new Engine(model, power, displacement, null));
                }
                else if (parameters.Length == 3)
                {
                    string efficiency = parameters[2];
                    engines.Add(new Engine(model, power, null, efficiency));
                }
                else if (parameters.Length == 4)
                {
                    string efficiency = parameters[3];
                    engines.Add(new Engine(model, power, int.Parse(parameters[2]), efficiency));
                }
                else
                {
                    engines.Add(new Engine(model, power, null, null));
                }
            }
            int carCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < carCount; i++)
            {
                string[] parameters  = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   model       = parameters[0];
                string   engineModel = parameters[1];
                Engine   engine      = engines.FirstOrDefault(x => x.model == engineModel);

                int weight = -1;

                if (parameters.Length == 3 && int.TryParse(parameters[2], out weight))
                {
                    cars.Add(new Car(model, engine, weight, null));
                }
                else if (parameters.Length == 3)
                {
                    string color = parameters[2];
                    cars.Add(new Car(model, engine, null, color));
                }
                else if (parameters.Length == 4)
                {
                    string color = parameters[3];
                    cars.Add(new Car(model, engine, int.Parse(parameters[2]), color));
                }
                else
                {
                    cars.Add(new Car(model, engine, null, null));
                }
            }

            foreach (var car in cars)
            {
                Console.WriteLine(car);
            }
        }
Ejemplo n.º 2
0
 public Car(string model, Engine engine, string color) : this(model, engine)
 {
     this.Weight = -1;
     this.Color  = color;
 }
Ejemplo n.º 3
0
 public Car(string model, Engine engine, int weight, string color) : this(model, engine, weight)
 {
     this.Color = color;
 }
Ejemplo n.º 4
0
 public Car(string model, Engine engine, int weight, string color)
     : this(model, engine, color)
 {
     this.Weight = weight;
 }
Ejemplo n.º 5
0
 public Car(string model, Engine engine, int weight) : this(model, engine)
 {
     this.Weight = weight;
     this.Color  = "n/a";
 }
Ejemplo n.º 6
0
 public Car(string model, Engine engine, int weight)
     : this(model, engine, weight, "n/a")
 {
 }
Ejemplo n.º 7
0
 public Car(string model, Engine engine, string color)
     : this(model, engine, -1, color)
 {
 }
Ejemplo n.º 8
0
 public Car(string model, Engine engine)
     : this(model, engine, -1, "n/a")
 {
 }
Ejemplo n.º 9
0
        public void AddEngine(string[] parameters)
        {
            Engine engine = engineFactory.Create(parameters);

            engines.Add(engine);
        }
Ejemplo n.º 10
0
 public Car(string model, Engine engine, int weight, string color)
     : this(model, engine)
 {
     Weight = weight;
     Color  = color;
 }
Ejemplo n.º 11
0
 public Car(string model, Engine engine, string color)
     : this(model, engine)
 {
     Color = color;
 }
Ejemplo n.º 12
0
 public Car(string model, Engine engine, int weight)
     : this(model, engine)
 {
     Weight = weight;
 }