Exemple #1
0
        static void Main(string[] args)
        {
            Console.Title = "TwoTanks by JenkaBY for Itibo, 2015";

            Console.WriteLine("Введите объем (в литрах) первой емкости Х (целое положительное число) \nX = ");
            int tank1NominalCapacity = int.Parse(Console.ReadLine());

            Console.WriteLine("Введите объем (в литрах) второй емкости Y (целое положительное число) \nY = ");
            int tank2NominalCapacity = int.Parse(Console.ReadLine());

            Console.WriteLine("Сколько литров вы хотите получить в одной из емкостей (целое положительное число) \nА =");
            int requiredVolume = int.Parse(Console.ReadLine());

            Tank X = new Tank() { NominalCapacity = tank1NominalCapacity, Name = "X" };
            Tank Y = new Tank() { NominalCapacity = tank2NominalCapacity, Name = "Y" };

            // checking different variations required volume
            //
            //int requiredVolume = 1;
            //for ( int i = 0;  i <= Y.NominalCapacity; i++)
            //{
            //    Console.WriteLine("-----------------" + i + "------------------------------");
            //    OperationWithTanks op = new OperationWithTanks(X, Y, i);
            //    op.Run();
            //    Console.WriteLine();
            //}

            OperationWithTanks op = new OperationWithTanks(X, Y, requiredVolume);
            op.Run();

            Console.ReadLine();
        }
 public OperationWithTanks(Tank tankA, Tank tankB, int RequiredVolume)
 {
     _requiredVolume = RequiredVolume;
     if (tankA.NominalCapacity > tankB.NominalCapacity)
     {
         this._bigger = tankA;
         this._lesser = tankB;
     }
     else
     {
         this._bigger = tankB;
         this._lesser = tankA;
     }
 }
        private void FillLesserFromBigger(Tank tankFrom, Tank tankTo)
        {
            int pastLesserVolume = tankTo.CurrentVolume;
            if ((tankFrom.CurrentVolume + tankTo.CurrentVolume) > tankTo.NominalCapacity)
            {
                tankTo.CurrentVolume = tankTo.NominalCapacity;
                tankFrom.CurrentVolume = tankFrom.CurrentVolume - tankTo.CurrentVolume + pastLesserVolume;
            }
            else
            {
                tankTo.CurrentVolume = tankFrom.CurrentVolume + tankTo.CurrentVolume;
                tankFrom.SetEmpty();
            }
            int different = tankTo.CurrentVolume - pastLesserVolume;
            _number++;

            this.Instruction.AppendFormat("{0}. Из емкости {1} переливаем {3}л в емкость {2} ({1} = {4}л, {2} = {5}л).\n",
                _number, tankFrom.Name, tankTo.Name, different, tankFrom.CurrentVolume, tankTo.CurrentVolume);
        }
 private void Fill(Tank tank)
 {
     tank.CurrentVolume = tank.NominalCapacity;
     _number++;
     this.Instruction.AppendFormat("{0}. Заполняем емкость {1} до конца ({1} = {2}л).\n", _number, tank.Name, tank.CurrentVolume);
 }
 private void UnFill(Tank tank)
 {
     tank.SetEmpty();
     _number++;
     this.Instruction.AppendFormat("{0}. Выливаем всю воду из емкости {1}({1} = {2}л).\n", _number, tank.Name, tank.CurrentVolume);
 }