Exemplo n.º 1
0
        static void Main(string[] args)
        {
            string hint = "If you change two numbers this means that water poured from one vessel to another\n" +
                          "If you change one number, it means that water is either poured or drawn from a hose\n";

            do
            {
                var waterTank1 = new WaterTank(EstablishLength("first"));
                var waterTank2 = new WaterTank(EstablishLength("second"));

                int amountOfLiters = int.Parse(EstablishVolume(waterTank1, waterTank2));
                if (GetGCD(waterTank1.GetMaximumCapacity(), waterTank2.GetMaximumCapacity()) > 1)
                {
                    Console.WriteLine("\n!!!The problem has no solution :(");
                }
                else
                {
                    var water = new Algorithm(waterTank1, waterTank2, amountOfLiters);

                    Console.WriteLine("\n!!!{0}", hint);

                    Console.WriteLine(water.GetInstruction());
                }

                Console.WriteLine("Enter the \"exit\" for exit");
                string answer = Console.ReadLine();
                if (answer.ToLower() == "exit") break;

                Console.Clear();
            } while (true);
        }
Exemplo n.º 2
0
 private static string EstablishVolume(WaterTank waterTank1, WaterTank waterTank2)
 {
     string amount;
     do
     {
         Console.Write("How many liters of water you need?: ");
         amount = Console.ReadLine();
     } while (amount == "" || !IsNumber(amount) ||
              (int.Parse(amount) > waterTank1.GetMaximumCapacity() && int.Parse(amount) > waterTank2.GetMaximumCapacity()));
     return amount;
 }
Exemplo n.º 3
0
        public Algorithm(WaterTank waterTank1, WaterTank waterTank2, int amountOfLiters)
        {
            if (waterTank2.GetMaximumCapacity() > waterTank1.GetMaximumCapacity())
            {
                this.WaterTank1 = waterTank2;
                this.WaterTank2 = waterTank1;
            }
            else
            {
                this.WaterTank1 = waterTank1;
                this.WaterTank2 = waterTank2;
            }

            _amountOfLiters = amountOfLiters;
        }