public bool MaxMileage()
        {
            bool succsesful = true;

            if (_fuelGauge.ReportLevel() > 0)
            {
                if (_currentMileage < _maxMileage)
                {
                    _currentMileage++;
                }
                else
                {
                    _currentMileage = 0;
                }

                if (_currentMileage % 10 == 0)
                {
                    _fuelGauge.DecreaseOfFuel();
                }
            }
            else
            {
                Console.WriteLine($"Fuel level is: {_fuelGauge.ReportLevel()}, please fill up your fuel tank!");
                succsesful = false;
            }
            return(succsesful);
        }
        public bool Increment()
        {
            bool success = true;

            if (_fuelGauge.ReportLevel() > 0)
            {
                if (_mileage < _maxMileage)
                {
                    _mileage++;
                }
                else
                {
                    _mileage = 0;
                }
                if (_mileage % 10 == 0)
                {
                    _fuelGauge.DecreaseLevel();
                }
            }
            else
            {
                //throw new Exception($"fuel level: {_fuelGauge.ReportLevel()}");
                Console.WriteLine($"Fuel level: {_fuelGauge.ReportLevel()}, please refill!");
                success = false;
            }

            return(success);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            FuelGauge fuelGauge      = new FuelGauge();
            Odometer  odometer       = new Odometer(fuelGauge);
            int       litersFilled   = 0;
            int       milesTravelled = 0;

            Console.WriteLine("Please enter liters filled:");
            litersFilled = int.Parse(Console.ReadLine());

            Console.WriteLine("Please enter miles travelled:");
            milesTravelled = int.Parse(Console.ReadLine());

            Console.Clear();

            for (var i = 0; i < litersFilled; i++)
            {
                fuelGauge.Fill();
            }
            Console.WriteLine($"Fuel gauge report: {fuelGauge.ReportLevel()}");

            for (int i = 0; i < milesTravelled; i++)
            {
                if (odometer.Increment())
                {
                    odometer.Increment();
                    Console.WriteLine($"Mileage: {odometer.Report()}, Fuel Level: {fuelGauge.ReportLevel()}");
                }
                else
                {
                    break;
                }
            }
            Console.ReadKey();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("New odometer");
            FuelGauge fuelGauge = new FuelGauge();
            Odometer  odometer  = new Odometer(fuelGauge);

            int filledLiters         = 7;
            int killometersTravelled = 101;

            for (int i = 0; i < filledLiters; i++)
            {
                fuelGauge.IncreaseOfFuel();
            }

            Console.WriteLine($"Fuel level: {fuelGauge.ReportLevel()}");
            Console.WriteLine("running");

            for (int i = 0; i < killometersTravelled; i++)
            {
                odometer.MaxMileage();
                odometer.ReportMileage();
                Console.WriteLine($"Odometer report: {odometer.ReportMileage()} km, Fuel level: {fuelGauge.ReportLevel()}");
            }


            Console.ReadLine();
        }
 public void Increment()
 {
     if (_fuelGauge.ReportLevel() > 0)
     {
         if (_mileage < _maxMileage)
         {
             _mileage++;
         }
         else
         {
             _mileage = 0;// te ir 2 dažādi if esle statement?
         }
         if (_mileage % 10 == 0)
         {
             _fuelGauge.DecreaseLevel();
         }
     }
     else//3 if else statemt?
     {
         throw new Exception(message: $"fuel level: {_fuelGauge.ReportLevel()}");// kāpēc te ir throw? nevajag catch?
     }
 }
        static void Main(string[] args)
        {
            Console.WriteLine("new odometer");
            var fuelGauge = new FuelGauge();//  jāuzpilda 10 reizes?

            for (int i = 0; i < 10; i++)
            {
                fuelGauge.Fill(); // fill strādā tikai priekš fuelGauge? Šī metode tiek izsaukta 10 reizes?
            }
            Console.WriteLine($"fuel level: {fuelGauge.ReportLevel()}");
            var odometer = new Odometer(fuelGauge);// odometra.cs jau ir rakstīts Odometer(fuelGauge). Kāpēc tas te tiek atkal rakstīts?

            Console.WriteLine("running...");

            for (int i = 0; i < 200; i++)
            {
                odometer.Increment();
                Console.WriteLine($"odometer report: {odometer.Report()}");
            }

            Console.ReadKey();//Kā redzēt kura darbība pēc kuras notiek? Ar breakpoint tikai apstājas tajā vietā
            //par ko ir jādomā lai šādies uzrakstītu? te viss ir 3 lapās.
        }
Exemple #7
0
        public void Increment()
        {
            if (_fuelGauge.ReportLevel() > 0)
            {
                if (_mileage < _maxMileage)
                {
                    _mileage++;
                }
                else
                {
                    _mileage = 0;
                }

                if (_mileage % 10 == 0)
                {
                    _fuelGauge.DecreaseLevel();
                }
            }
            else
            {
                throw new Exception($"no fuel");
            }
        }
Exemple #8
0
        static void Main(string[] args)
        {
            var fuelGauge = new FuelGauge();
            var odometr   = new Odometer(fuelGauge);



            for (var i = 0; i < 7; i++)
            {
                fuelGauge.Fill();
            }

            for (var i = 0; i < 101; i++)
            {
                odometr.Increment();
                Console.WriteLine(odometr.ReportMileage());
                Console.WriteLine(fuelGauge.ReportLevel() + "litri");

                Console.ReadKey();
            }


            Console.ReadKey();
        }