public Program3()
        {
            MyCar   = new Car(true, "Citroen", "Saxo");
            MyLorry = new Lorry(true, "Mercades", "Actros");

            CurrentAutomobile = AutomobileType.Car;
        }
        public Program4()
        {
            MyHatchback = new Hatchback(true, "Citroen", "Saxo", true, "petrol");
            MySaloon    = new Saloon(true, "Audi", "A3", true, "diesel");
            MyLorry     = new Lorry(true, "Mercades", "Actros", true, "petrol");

            CurrentAutomobile = AutomobileType.Hatchback;
        }
Beispiel #3
0
        public Program5()
        {
            Engine myHatchbackEngine = new Engine(1400);

            MyHatchback = new Hatchback(myHatchbackEngine, true, "Citroen", "Saxo", true, "petrol");

            Engine mySaloonEngine = new Engine(1800);

            MySaloon = new Saloon(mySaloonEngine, true, "Audi", "A3", true, "diesel");

            Engine myLorryEngine = new Engine(2000);

            MyLorry = new Lorry(myLorryEngine, true, "Mercades", "Actros", true, "petrol");

            CurrentAutomobile = AutomobileType.Hatchback;
        }
Beispiel #4
0
        public IAutomobile make(AutomobileType type)
        {
            IAutomobile automobile = null;

            if (type == AutomobileType.Audi)
            {
                automobile = new Audi();
            }
            else if (type == AutomobileType.BMW)
            {
                automobile = new BMW();
            }
            else if (type == AutomobileType.Tesla)
            {
                automobile = new Tesla();
            }
            else
            {
                Console.WriteLine("Sorry! there is no car having this name");
                return(null);
            }
            return(automobile);
        }
Beispiel #5
0
        public void Run(string command)
        {
            if (command.StartsWith("switch"))
            {
                switch (CurrentAutomobile)
                {
                case AutomobileType.Hatchback: CurrentAutomobile = AutomobileType.Saloon;
                    Console.WriteLine("You have switched to a Saloon\n");
                    break;

                case AutomobileType.Saloon: CurrentAutomobile = AutomobileType.Lorry;
                    Console.WriteLine("You have switched to a Lorry\n");
                    break;

                case AutomobileType.Lorry: CurrentAutomobile = AutomobileType.Hatchback;
                    Console.WriteLine("You have switched to a Hatchback\n");
                    break;
                }
            }

            else if (command.StartsWith("get info"))
            {
                Console.WriteLine(GetAutomobile().GetInfo());
            }

            else if (command.StartsWith("service"))
            {
                Console.WriteLine(GetAutomobile().Engine.Service());
            }

            else if (command.StartsWith("lock"))
            {
                ReturnValue ret = GetAutomobile().Lock();
                if (ret.Success)
                {
                    Console.WriteLine(ret.Message);
                }
            }

            else if (command.StartsWith("unlock"))
            {
                if (CurrentAutomobile == AutomobileType.Hatchback)
                {
                    ReturnValue ret = MyHatchback.Unlock();
                    if (ret.Success)
                    {
                        Console.WriteLine(ret.Message);
                    }
                }
                else if (CurrentAutomobile == AutomobileType.Saloon)
                {
                    Console.WriteLine("Please provide a code.");;
                    string      code = Console.ReadLine().ToLower();
                    ReturnValue ret  = MySaloon.Unlock(code);
                    if (ret.Success)
                    {
                        Console.WriteLine(ret.Message);
                    }
                }

                else if (CurrentAutomobile == AutomobileType.Lorry)
                {
                    ReturnValue ret = MyLorry.Unlock();
                    if (ret.Success)
                    {
                        Console.WriteLine(ret.Message);
                    }
                }
            }

            else if (command.StartsWith("add fuel")) // Check string
            {
                try
                {
                    while (true)
                    {
                        Console.WriteLine("How much fuel?");
                        string      commandAmount = Console.ReadLine();
                        decimal     fuelAmount    = Decimal.Parse(commandAmount);
                        ReturnValue retAmount     = GetAutomobile().CheckFuelAmount(fuelAmount);

                        if (retAmount.Success)
                        {
                            if (CurrentAutomobile == AutomobileType.Saloon)
                            {
                                Console.WriteLine("What fuel type to add?");
                                string      fuelTypeAdd = Console.ReadLine().ToLower();
                                ReturnValue retType     = GetAutomobile().CheckFuelType(fuelTypeAdd);

                                if (retType.Success)
                                {
                                    Console.WriteLine(GetAutomobile().AddFuel(fuelAmount));
                                    break;
                                }
                                else
                                {
                                    Console.WriteLine(retType.Message);
                                    break;
                                }
                            }
                            else
                            {
                                Console.WriteLine(GetAutomobile().AddFuel(fuelAmount));
                                break;
                            }
                        }
                        else
                        {
                            Console.WriteLine(retAmount.Message);
                            break;
                        }
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Sorry an error occurred trying to add the fuel. \n");
                }
            }

            else if (command.StartsWith("drive"))
            {
                try
                {
                    Console.WriteLine("How many miles?");

                    string  commandAmount = Console.ReadLine();
                    decimal mileageAmount = Decimal.Parse(commandAmount);

                    ReturnValue ret = GetAutomobile().Plan(mileageAmount);

                    if (ret.Success == true)
                    {
                        Console.WriteLine(ret.Message);
                        string commandDrive = Console.ReadLine().ToLower();
                        if (commandDrive.StartsWith("y"))
                        {
                            if (GetAutomobile().Locked.Equals(false))
                            {
                                Console.WriteLine(GetAutomobile().Drive(mileageAmount));
                            }
                            else
                            {
                                Console.WriteLine("You need to unlock your " + CurrentAutomobile + ".\n");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Ok then. \n");
                        }
                    }
                    else
                    {
                        Console.WriteLine(ret.Message);
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Sorry an error occurred trying to add mileage \n");
                }
            }

            else if (command.StartsWith("reverse"))
            {
                Console.WriteLine(GetAutomobile().Reverse());
            }

            else
            {
                Console.WriteLine("Sorry I didn't catch that? \n");
            }
        }
        public void Run(string command)
        {
            if (command.StartsWith("switch"))
            {
                switch (CurrentAutomobile)
                {
                case AutomobileType.Car: CurrentAutomobile = AutomobileType.Lorry;
                    Console.WriteLine("You have switched to a Lorry\n");
                    break;

                case AutomobileType.Lorry: CurrentAutomobile = AutomobileType.Car;
                    Console.WriteLine("You have switched to a Car\n");
                    break;
                }
            }

            else if (command.StartsWith("get info"))
            {
                Console.WriteLine(GetAutomobile().GetInfo());
            }

            else if (command.StartsWith("add fuel")) // Check string
            {
                try
                {
                    while (true)
                    {
                        Console.WriteLine("How much fuel?");

                        string  commandAmount = Console.ReadLine();
                        decimal fuelAmount    = Decimal.Parse(commandAmount);

                        ReturnValue ret = GetAutomobile().AddFuel(fuelAmount);

                        if (ret.Success == true)
                        {
                            Console.WriteLine(ret.Message);
                            break;
                        }
                        else
                        {
                            Console.WriteLine(ret.Message);
                            string commandRetry = Console.ReadLine().ToLower();
                            if (commandRetry.StartsWith("n"))
                            {
                                Console.WriteLine("Ok then. \n");
                                break;
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Sorry an error occurred trying to add the fuel. \n");
                }
            }

            else if (command.StartsWith("plan"))
            {
                try
                {
                    Console.WriteLine("How many miles?");

                    string  commandAmount = Console.ReadLine();
                    decimal mileageAmount = Decimal.Parse(commandAmount);

                    ReturnValue ret = GetAutomobile().Plan(mileageAmount);

                    if (ret.Success == true)
                    {
                        Console.WriteLine(ret.Message);
                        string commandDrive = Console.ReadLine().ToLower();
                        if (commandDrive.StartsWith("y"))
                        {
                            Console.WriteLine(GetAutomobile().Drive(mileageAmount));
                        }
                        else
                        {
                            Console.WriteLine("Ok then. \n");
                        }
                    }
                    else
                    {
                        Console.WriteLine(ret.Message);
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Sorry an error occurred trying to add mileage \n");
                }
            }

            else
            {
                Console.WriteLine("Sorry I didn't catch that? \n");
            }
        }