Exemplo n.º 1
0
        public static void FuelSort(VehicleAgency obj)
        {
            Car tmpi, tmpj, buff;

            for (int i = 0; i < obj.Size; i++)
            {
                if (obj[i] is Car)
                {
                    tmpi = (Car)obj[i];
                    for (int j = i; j < obj.Size; j++)
                    {
                        if (obj[j] is Car)
                        {
                            tmpj = (Car)obj[j];
                            if (tmpi.Fuel > tmpj.Fuel)
                            {
                                buff   = tmpi;
                                tmpi   = tmpj;
                                tmpj   = buff;
                                obj[i] = tmpi;
                                obj[j] = tmpj;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static int Sum(VehicleAgency obj)
        {
            int sum = 0;

            for (int i = 0; i < obj.Size; i++)
            {
                sum += obj[i].Price;
            }
            return(sum);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Car c1 = new Car(100, 200, 8);

            c1.Speed = 100;
            Car     c2   = new Car(100, 100, 4);
            Car     c3   = new Car(100, 300, 5);
            Train   tr1  = new Train(600, 10000, "Stolin", "Blue", 3);
            Express exp1 = new Express(500, 200000, "Minsk", "Red", 10, true);
            Engine  eng1 = new Engine(200);

            Console.WriteLine(c1.ToString());
            Console.WriteLine(tr1.ToString());
            Console.WriteLine(exp1.ToString());
            Console.WriteLine(eng1.ToString());
            Printer p = new Printer();

            c1.Move();
            Console.WriteLine(c1.Status);
            c1.ChangeStatus();
            c1.Move();
            Console.WriteLine(c1.Status);
            exp1.Move();
            Console.WriteLine(exp1.Speed);
            Engine[] eng = new Engine[4];
            eng[0] = c1;
            eng[1] = tr1;
            eng[2] = exp1;
            eng[3] = eng1;
            for (int i = 0; i < 4; i++)
            {
                p.iAmPrinting(eng[i]);
            }
            VehicleAgency va = new VehicleAgency();

            va.Add(c1);
            va.Add(c2);
            va.Add(c3);
            va.Add(tr1);
            va.Add(eng1);
            va.Add(exp1);
            Controller.FuelSort(va);
            va.iAmPrinting(va.get(0));
            va.iAmPrinting(va.get(1));
            va.iAmPrinting(va.get(2));
            Console.WriteLine(va.get(3).Status);
            Console.WriteLine(Controller.Sum(va));
            Engine eng2 = new Engine(300);

            eng2 = Controller.SpeedSearch(va, 50, 200);
            p.iAmPrinting(eng2);
            Console.ReadKey();
        }
Exemplo n.º 4
0
        public static Engine SpeedSearch(VehicleAgency obj, int min, int max)
        {
            Engine  res  = null;
            Car     tmpc = new Car();
            Train   tmpt = new Train();
            Express tmpe = new Express();

            for (int i = 0; i < obj.Size; i++)
            {
                if (obj[i] is Car)
                {
                    tmpc = (Car)obj[i];
                    if (tmpc.Speed > min && tmpc.Speed < max)
                    {
                        res = (Engine)obj[i];
                        break;
                    }
                }
                else if (obj[i] is Train)
                {
                    tmpt = (Train)obj[i];
                    if (tmpt.Speed > min && tmpt.Speed < max)
                    {
                        res = (Engine)obj[i];
                        break;
                    }
                }
                else if (obj[i] is Express)
                {
                    tmpe = (Express)obj[i];
                    if (tmpe.Speed > min && tmpe.Speed < max)
                    {
                        res = (Engine)obj[i];
                        break;
                    }
                }
            }
            return(res);
        }
Exemplo n.º 5
0
 static void Main(string[] args)
 {
     try
     {
         Car c1 = new Car(100, 200, 8);
         c1.Speed = 100;
         Car     c2   = new Car(100, 100, 4);
         Car     c3   = new Car(100, 300, 5);
         Train   tr1  = new Train(600, 10000, "Stolin", "Blue", 3);
         Express exp1 = new Express(500, 200000, "Minsk", "Red", 10, true);
         Engine  eng1 = new Engine(200);
         Console.WriteLine(c1.ToString());
         Console.WriteLine(tr1.ToString());
         Console.WriteLine(exp1.ToString());
         Console.WriteLine(eng1.ToString());
         Printer p = new Printer();
         c1.Move();
         Console.WriteLine(c1.Status);
         c1.ChangeStatus();
         c1.Move();
         Console.WriteLine(c1.Status);
         exp1.Move();
         Console.WriteLine(exp1.Speed);
         Engine[] eng = new Engine[4];
         eng[0] = c1;
         eng[1] = tr1;
         eng[2] = exp1;
         eng[3] = eng1;
         for (int i = 0; i < 4; i++)
         {
             p.iAmPrinting(eng[i]);
         }
         VehicleAgency va = new VehicleAgency();
         //int c = va[0].Power;
         va.Add(c1);
         va.Add(c2);
         va.Add(c3);
         va.Add(tr1);
         va.Add(eng1);
         va.Add(exp1);
         //Debug.Assert(5!=5,"Стоп");
         Controller.FuelSort(va);
         va.iAmPrinting(va.get(0));
         va.iAmPrinting(va.get(1));
         va.iAmPrinting(va.get(2));
         Console.WriteLine(va.get(3).Status);
         Console.WriteLine(Controller.Sum(va));
         Engine eng2 = new Engine(300);
         eng2 = Controller.SpeedSearch(va, 50, 200);
         p.iAmPrinting(eng2);
         //tr1.Amount = -100;
         //int c = va[100].Power;
         //va[10].Power = 100;
         Console.ReadKey();
     }
     catch (SolveException e)
     {
         Console.WriteLine(e.Message + " [" + e.Index + "] " + "Решение: " + e.Solve);
         Console.ReadKey();
     }
     catch (LimitException e)
     {
         Console.WriteLine(e.Message + " [" + e.Index + "]");
         Console.ReadKey();
     }
     catch (UnsignedException e)
     {
         Console.WriteLine(e.Message + " " + e.Source);
         Console.ReadKey();
     }
     catch
     {
         Console.WriteLine("Неизвестная ошибка");
     }
     finally
     {
         Console.WriteLine("Блок finally");
         Console.ReadKey();
     }
 }