static void Main(string[] args)
        {
            HybridCar Toyota = new HybridCar(24, 8, "100009");

            Console.WriteLine(Toyota.MotorNumber);
            Console.ReadLine();
        }
        private void UpdateCar()
        {
            Console.Clear();

            Console.Write("Enter the name of the car you wish to update: ");
            string name = Console.ReadLine();

            ICar carToUpdate = _carRepo.GetCarByName(name);

            if (carToUpdate is GasCar)
            {
                carToUpdate = GasCarSetup(true);
                GasCar gasCarToUpdate = (GasCar)Convert.ChangeType(carToUpdate, typeof(GasCar));
                gasCarToUpdate.Name = name;
                if (_carRepo.UpdateGasCar(name, gasCarToUpdate))
                {
                    Console.WriteLine("Car updated successfully.\n");
                }
                else
                {
                    Console.WriteLine("Invalid. Returning to main menu.\n");
                }
            }
            else if (carToUpdate is HybridCar)
            {
                carToUpdate = HybridCarSetup(true);
                HybridCar hybridCarToUpdate = (HybridCar)Convert.ChangeType(carToUpdate, typeof(HybridCar));
                hybridCarToUpdate.Name = name;
                if (_carRepo.UpdateHybridCar(name, hybridCarToUpdate))
                {
                    Console.WriteLine("Car updated successfully.\n");
                }
                else
                {
                    Console.WriteLine("Invalid. Returning to main menu.\n");
                }
            }
            else if (carToUpdate is ElectricCar)
            {
                carToUpdate = ElectricCarSetup(true);
                ElectricCar electricCarToUpdate = (ElectricCar)Convert.ChangeType(carToUpdate, typeof(ElectricCar));
                electricCarToUpdate.Name = name;
                if (_carRepo.UpdateElectricCar(name, electricCarToUpdate))
                {
                    Console.WriteLine("Car updated successfully.\n");
                }
                else
                {
                    Console.WriteLine("Invalid. Returning to main menu.\n");
                }
            }
            else
            {
                Console.WriteLine("Something went wrong.\n");
            }
            PressAnyKey();
        }
        private void SeedCars()
        {
            GasCar      gasCar      = new GasCar("Honda", 8000, 85.6, 24.5, 15.4, 30);
            HybridCar   hybridCar   = new HybridCar("Mercedes", 6000, 70.2, 50.3, 42.8, 20, 15);
            ElectricCar electricCar = new ElectricCar("Tesla", 4000, 90.6, 20.1, 30.2, 24.1);

            _carRepo.CreateCar(gasCar);
            _carRepo.CreateCar(hybridCar);
            _carRepo.CreateCar(electricCar);
        }
Пример #4
0
        private static void StrategyDemo()
        {
            var hybridCar = new HybridCar(new PetrolMove());

            hybridCar.Move();

            hybridCar.Strategy = new ElectricMove();

            hybridCar.Move();
        }
Пример #5
0
        /// <summary>
        /// Событие при нажатии кнопки выгрузки БД
        /// </summary>
        private void CompileDatabase(object sender, EventArgs e)
        {
            try
            {
                DataSet   ds = new DataSet();
                DataTable dt = new DataTable();
                dt.TableName = "Vehicles";
                dt.Columns.Add("Name");
                dt.Columns.Add("OilConsumption");
                dt.Columns.Add("Speed");
                dt.Columns.Add("TypeOfVehicle");
                dt.Columns.Add("Economy");
                dt.Columns.Add("NumbersOfEngine");
                ds.Tables.Add(dt);
                foreach (VehicleBase vehicle in _vehicles)
                {
                    DataRow row = ds.Tables["Vehicles"].NewRow();
                    row["Name"]           = vehicle.Name;
                    row["OilConsumption"] = vehicle.OilConsumption;
                    row["Speed"]          = vehicle.Speed;
                    row["TypeOfVehicle"]  = vehicle.TypeOfVehicle;
                    if (vehicle is HybridCar)
                    {
                        HybridCar Hubrid = vehicle as HybridCar;
                        row["Economy"] = Hubrid.Economy;
                    }
                    if (vehicle is Helicopter)
                    {
                        Helicopter Helicopter = vehicle as Helicopter;
                        row["NumbersOfEngine"] = Helicopter.NumbersOFEngine;
                    }
                    ds.Tables["Vehicles"].Rows.Add(row);
                }
                Stream         myStream;
                SaveFileDialog saveFileDialog1 = new SaveFileDialog();

                saveFileDialog1.Filter           = "myfile (*.myfile)|*.myfile|All files (*.*)|*.*";
                saveFileDialog1.FilterIndex      = 2;
                saveFileDialog1.RestoreDirectory = true;

                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    if ((myStream = saveFileDialog1.OpenFile()) != null)
                    {
                        ds.WriteXml(myStream);
                        myStream.Close();
                        MessageBox.Show("MyFile saved succesfully", "Done.");
                    }
                }
            }
            catch
            {
                MessageBox.Show("Can not save .myfile .", "not success.");
            }
        }
Пример #6
0
        public void UpdateCarOnListTest()
        {
            HybridCar carThree = new HybridCar("Nissan", "Blend", 85.99d, 17500.50m, 3);

            _carsList.UpdateCarOnList("Prius", carThree);

            var actual = _carsList.GetCarFromList("Blend");

            Assert.AreEqual(carThree.MPG, actual.MPG);
            Assert.AreEqual(carThree.NumberOfDrivers, actual.NumberOfDrivers);
            Assert.AreEqual(carThree.Price, actual.Price);
        }
Пример #7
0
        private static void StrategyTest()
        {
            Console.WriteLine("---------------------------");
            Console.WriteLine("StrategyTest");
            var car = new HybridCar(new PetrolMove());

            car.Move();
            car.SetStrategy(new ElectricMove());
            car.Move();

            Console.WriteLine("---------------------------");
        }
        public void AddCar_ShouldGetCorrectBool() //Create
        {
            //Arrange
            HybridCar hybridCar = new HybridCar();
            Car_Repo  repo      = new Car_Repo();

            //Act
            bool addResult = repo.AddCar(hybridCar);


            //Assert
            Assert.IsTrue(addResult);
        }
        private void SeedCarList()
        {
            HybridCar   carOne   = new HybridCar("Nissan", "Blend", 85.99d, 17500.50m, 3);
            HybridCar   carTwo   = new HybridCar("Toyota", "Prius", 85.00d, 18000.00m, 25);
            GasCar      carThree = new GasCar("Nissan", "Versa", 32.5d, 140000.00m, 14);
            GasCar      carFour  = new GasCar("Scion", "xD", 26d, 135000.00m, 4);
            ElectricCar carFive  = new ElectricCar("Tesla", "Model S", 154.0d, 390000.00m, 10);
            ElectricCar carSix   = new ElectricCar("Chevrolet", "Bolt", 95.0d, 360000.00m, 25);

            _carsList.AddCarToList(carOne);
            _carsList.AddCarToList(carTwo);
            _carsList.AddCarToList(carThree);
            _carsList.AddCarToList(carFour);
            _carsList.AddCarToList(carFive);
            _carsList.AddCarToList(carSix);
        }
Пример #10
0
        public void SeedCars()
        {
            GasCar      car  = new GasCar("Ford", "Mustang", 2020, VehicleType.SportsCar, 100, 19);
            GasCar      car2 = new GasCar("Toyota", "Camry", 2019, VehicleType.Sedan, 624, 32);
            HybridCar   car3 = new HybridCar("Toyota", "Prius", 2020, VehicleType.Sedan, 655, 52, 8.8);
            HybridCar   car4 = new HybridCar("Honda", "Accord Hybrd", 2020, VehicleType.Sedan, 614.4, 48, 1.3);
            ElectricCar car5 = new ElectricCar("Tesla", "ModelS", 2020, VehicleType.Sedan, 322, 75, 10);
            ElectricCar car6 = new ElectricCar("Hyundai", "Kona", 2020, VehicleType.HatchBack, 258, 64, 9);

            _repo.AddCar(car);
            _repo.AddCar(car2);
            _repo.AddCar(car3);
            _repo.AddCar(car4);
            _repo.AddCar(car5);
            _repo.AddCar(car6);
        }
        private void UpdateCarOnList()
        {
            Console.Write("Please enter the current model name of the car you'd like to update: ");
            string oldModel = Console.ReadLine();

            Console.Write("Please enter the new make of the car you'd like to update: ");
            string make = Console.ReadLine();

            Console.Write("Please enter the new model of the car you'd like to update: ");
            string model = Console.ReadLine();

            Console.Write("How many miles per gallon does this updated car get? (or electric charge equivalent): ");
            double mpg = double.Parse(Console.ReadLine());

            Console.Write("What is the new price of the car?: $");
            decimal price = decimal.Parse(Console.ReadLine());

            Console.Write("How many customers now drive this car?: ");
            int numberOfDrivers = int.Parse(Console.ReadLine());

            Console.Write("What type of car is being updated (electric, hybrid, or gas)?: ");
            string carType = Console.ReadLine();

            if (carType.ToLower() == "electric")
            {
                ElectricCar eCar = new ElectricCar(make, model, mpg, price, numberOfDrivers);
                _carsList.UpdateCarOnList(oldModel, eCar);
            }
            else if (carType.ToLower() == "hybrid")
            {
                HybridCar hCar = new HybridCar(make, model, mpg, price, numberOfDrivers);
                _carsList.UpdateCarOnList(oldModel, hCar);
            }
            else if (carType.ToLower() == "gas")
            {
                GasCar gCar = new GasCar(make, model, mpg, price, numberOfDrivers);
                _carsList.UpdateCarOnList(oldModel, gCar);
            }
            else
            {
                Console.WriteLine("Please enter electric, hybrid, or gas");
            }
            Console.WriteLine("Car added\n" +
                              "Press any key to continue...");
            Console.ReadKey();
        }
        public void GetCarByID_ShouldReturnCorrectCar()//Read
        {
            //Arrange
            GasCar    car  = new GasCar("ford", "mustang", 2020);
            HybridCar car2 = new HybridCar("toyota", "prius", 2019);
            Car_Repo  repo = new Car_Repo();

            repo.AddCar(car);
            repo.AddCar(car2);

            string id = "2020fordmustang";

            //Act
            var localCar = repo.GetCarByID(id);

            //assert
            Assert.AreEqual(localCar.CarID, id);
        }
        public void AddCarToRepository_ShouldReturnTrue()
        {
            //Arrange
            CarRepository repo     = new CarRepository();
            ElectricCar   electric = new ElectricCar();
            GasCar        gas      = new GasCar();
            HybridCar     hybrid   = new HybridCar();

            //Act
            bool expected1 = repo.AddCar(electric);
            bool expected2 = repo.AddCar(gas);
            bool expected3 = repo.AddCar(hybrid);

            //Assert
            Assert.IsTrue(expected1);
            Assert.IsTrue(expected2);
            Assert.IsTrue(expected3);
        }
        private void AddCar()
        {
            Console.Write("Please enter the make of the car you'd like to add: ");
            string make = Console.ReadLine();

            Console.Write("Please enter the model of the car you'd like to add: ");
            string model = Console.ReadLine();

            Console.Write("How many miles per gallon does this car get? (or electric charge equivalent): ");
            double mpg = double.Parse(Console.ReadLine());

            Console.Write("What is the price of the car?: $");
            decimal price = decimal.Parse(Console.ReadLine());

            Console.Write("How many customers drive this car?: ");
            int numberOfDrivers = int.Parse(Console.ReadLine());

            Console.Write("Is this car electric, hybrid, or gas?: ");
            string carType = Console.ReadLine();

            if (carType.ToLower() == "electric")
            {
                ElectricCar eCar = new ElectricCar(make, model, mpg, price, numberOfDrivers);
                _carsList.AddCarToList(eCar);
            }
            else if (carType.ToLower() == "hybrid")
            {
                HybridCar hCar = new HybridCar(make, model, mpg, price, numberOfDrivers);
                _carsList.AddCarToList(hCar);
            }
            else if (carType.ToLower() == "gas")
            {
                GasCar gCar = new GasCar(make, model, mpg, price, numberOfDrivers);
                _carsList.AddCarToList(gCar);
            }
            else
            {
                Console.WriteLine("Please enter electric, hybrid, or gas");
            }
            Console.WriteLine("Car added\n" +
                              "Press any key to continue...");
            Console.ReadKey();
        }
        public void Arrange()
        {
            ElectricCar electric1 = new ElectricCar("Tesla", "tesla", 2010, 45);

            _testRepo.AddCar(electric1);

            ElectricCar electric2 = new ElectricCar("Chevy", "Volt", 2019, 42);

            _testRepo.AddCar(electric2);

            ElectricCar electric3 = new ElectricCar("Hiii", "Whatup", 2018, 40);

            _testRepo.AddCar(electric3);

            HybridCar hybrid1 = new HybridCar("Toyota", "Prius", 2020, 38);

            _testRepo.AddCar(hybrid1);

            HybridCar hybrid2 = new HybridCar("Honda", "Something-something", 2019, 39);

            _testRepo.AddCar(hybrid2);

            HybridCar hybrid3 = new HybridCar("Ford", "Another Hybrid", 2017, 39);

            _testRepo.AddCar(hybrid3);

            GasCar gasCar1 = new GasCar("Chevy", "Cruze", 2019, 29);

            _testRepo.AddCar(gasCar1);

            GasCar gasCar2 = new GasCar("Ford", "Focus", 2016, 32);

            _testRepo.AddCar(gasCar2);

            GasCar gasCar3 = new GasCar("Audi", "Q5", 2019, 33);

            _testRepo.AddCar(gasCar3);

            GasCar gasCar4 = new GasCar("Mercedes", "C300", 2018, 28);

            _testRepo.AddCar(gasCar4);
        }
Пример #16
0
        public void SeedContent()
        {
            ICar eCarOne = new ElectricCar(101, "Tesla", "Model S", 2019, 5000.05);

            _carRepository.AddCarToList(eCarOne);
            ICar eCarTwo = new ElectricCar(102, "Tesla", "Model 3", 2019, 4500.05);

            _carRepository.AddCarToList(eCarTwo);
            ICar gCarOne = new GasCar(201, "Toyota", "Yaris", 2007, 175000);

            _carRepository.AddCarToList(gCarOne);
            ICar gCarTwo = new GasCar(202, "Chrysler", "Town & Country", 2012, 105000);

            _carRepository.AddCarToList(gCarTwo);
            ICar hCarOne = new HybridCar(301, "Toyota", "Prius C", 2014, 65000.50);

            _carRepository.AddCarToList(hCarOne);
            ICar hCarTwo = new HybridCar(302, "Toyota", "Prius L", 2019, 6874);

            _carRepository.AddCarToList(hCarTwo);
        }
        public void SeedCars()
        {
            var gasCar1 = new GasCar("Honda", "Civic", "2020", 1000, 25);
            var gasCar2 = new GasCar("Toyota", "Camry", "2020", 800, 30);
            var gasCar3 = new GasCar("Hyundai", "Sonata", "2020", 1200, 28);
            var hybrid1 = new HybridCar("Toyota", "Prius", "2020", 1500, 80, 100);
            var hybrid2 = new HybridCar("Chevy", "Bolt", "2020", 1500, 80, 80);
            var hybrid3 = new HybridCar("Hyundai", "Hybrid", "2020", 2500, 50, 80);
            var ele1    = new ElectricCar("Tesla", "Model S", "2020", 2000, 300);
            var ele2    = new ElectricCar("Tesla", "Model X", "2020", 2300, 300);
            var ele3    = new ElectricCar("Tesla", "Model Y", "2020", 2100, 350);

            _cars.AddCarToDirectory(gasCar1);
            _cars.AddCarToDirectory(gasCar2);
            _cars.AddCarToDirectory(gasCar3);
            _cars.AddCarToDirectory(hybrid1);
            _cars.AddCarToDirectory(hybrid2);
            _cars.AddCarToDirectory(hybrid3);
            _cars.AddCarToDirectory(ele1);
            _cars.AddCarToDirectory(ele2);
            _cars.AddCarToDirectory(ele3);
        }
Пример #18
0
        public void UpdateACar()
        {
            Console.WriteLine("Update a car \n" +
                              "Enter first name of car owner: ");
            string firstName = Console.ReadLine();
            ICar   car       = _carRepo.GetACar(firstName);

            Console.WriteLine($"{car.FirstName} - {car.CarPrice} - {car.CarType}");
            Console.WriteLine("Please enter new car owner name: ");
            string newFirstName = Console.ReadLine();

            Console.WriteLine("Enter new car price: ");
            decimal carPrice = decimal.Parse(Console.ReadLine());

            Console.WriteLine("Choose new Car Type: \n" +
                              "1. Electric\n" +
                              "2. Hybrid\n" +
                              "3. Gas");
            TypeOfCar carType = (TypeOfCar)int.Parse(Console.ReadLine());

            if (carType == TypeOfCar.Electric)
            {
                ElectricCar newCar = new ElectricCar(TypeOfCar.Electric, carPrice, firstName);
                _carRepo.UpdateElectricCar(firstName, newCar);
            }
            else if (carType == TypeOfCar.Hybrid)
            {
                HybridCar newCar = new HybridCar(TypeOfCar.Hybrid, carPrice, firstName);
                _carRepo.UpdateHybridCar(firstName, newCar);
            }
            else if (carType == TypeOfCar.Gas)
            {
                GasCar newCar = new GasCar(TypeOfCar.Gas, carPrice, firstName);
                _carRepo.UpdateGasCar(firstName, newCar);
            }

            Console.WriteLine($"{car.FirstName} - {car.CarPrice} - {car.CarType}");
            Console.ReadKey();
        }
Пример #19
0
        /// <summary>
        /// Событие по нажатию кнопки рандомного задания ТС
        /// </summary>
        private void GetRandomVehicle(object sender, EventArgs e)
        {
            try
            {
                dataGridView2.Columns.Clear();
                dataGridView2.AllowUserToAddRows = true;
                Randomizer randomize = new Randomizer();

                var randomNumber = randomize.Next(0, 3);
                switch (randomNumber)
                {
                case 0:
                {
                    Vehicle = Car.RandomCar();
                    break;
                }

                case 1:
                {
                    Vehicle = HybridCar.RandomHybridCar();
                    break;
                }

                case 2:
                {
                    Vehicle = Helicopter.RandomHelicopter();
                    break;
                }
                }

                dataGridView2.DataSource = Vehicle;
                this.Close();
            }
            catch
            {
                MessageBox.Show("Что-то пошло не так при рандомной генерации");
            }
        }
        private IHybridCar HybridCarSetup(bool isUpdating)
        {
            HybridCar newHybridCar = new HybridCar();

            if (isUpdating == false)
            {
                Console.Write("\nEnter the name of the car: ");
                newHybridCar.Name = Console.ReadLine();
            }
            Console.Write("\nEnter the weight of the car (in whole number lbs.): ");
            newHybridCar.Weight = int.Parse(Console.ReadLine());
            Console.Write("\nEnter the top speed of the car (MPH): ");
            newHybridCar.TopSpeed = double.Parse(Console.ReadLine());
            Console.Write("\nEnter the MPG in the country of the car: ");
            newHybridCar.MPGCountry = double.Parse(Console.ReadLine());
            Console.Write("\nEnter the MPG on the highway of the car: ");
            newHybridCar.MPGHighway = double.Parse(Console.ReadLine());
            Console.Write("\nEnter the tank capacity of the car (whole number gallons): ");
            newHybridCar.TankCapacity = int.Parse(Console.ReadLine());
            Console.Write("\nEnter the battery capacity of the car (in kWh): ");
            newHybridCar.BatteryCapacity = double.Parse(Console.ReadLine());

            return(newHybridCar);
        }
        public void NewHybridCar()
        {
            bool addNewCar      = false;
            bool chooseMake     = false;
            bool chooseModel    = false;
            bool chooseYear     = false;
            bool chooseCTD      = false;
            bool chooseMPG      = false;
            bool chooseDistance = false;
            bool chooseChanges  = false;
            bool makeChanges    = false;
            var  newCar         = new HybridCar();

            while (addNewCar == false)
            {
                Console.Clear();
                chooseChanges = false;
                while (chooseMake == false)
                {
                    chooseMake = true;
                    Console.WriteLine("What is the make of this car?");
                    newCar.Make = Console.ReadLine();
                    Console.Clear();
                }
                while (chooseModel == false)
                {
                    chooseModel = true;
                    Console.WriteLine("What is the model of this car?");
                    newCar.Model = Console.ReadLine();
                    Console.Clear();
                }
                while (chooseYear == false)
                {
                    chooseYear = true;
                    Console.WriteLine("What is the year of this car? (yyyy)");
                    newCar.Year = Console.ReadLine();
                    Console.Clear();
                }
                while (chooseCTD == false)
                {
                    chooseCTD = true;
                    Console.WriteLine("How much does this car cost per year to drive?");
                    try
                    {
                        newCar.CostToDrivePerYear = int.Parse(Console.ReadLine());
                        Console.Clear();
                    }
                    catch (Exception)
                    {
                        Console.Clear();
                        Console.WriteLine("Invalid selection. \nPress any key to continue...");
                        Console.ReadKey();
                        Console.Clear();
                        chooseCTD = false;
                    }
                }
                while (chooseMPG == false)
                {
                    chooseMPG = true;
                    Console.WriteLine("What is this car's MPG?");
                    try
                    {
                        newCar.MPG = int.Parse(Console.ReadLine());
                        Console.Clear();
                    }
                    catch (Exception)
                    {
                        Console.Clear();
                        Console.WriteLine("Invalid selection. \nPress any key to continue...");
                        Console.ReadKey();
                        Console.Clear();
                        chooseDistance = false;
                    }
                }
                while (chooseDistance == false)
                {
                    chooseDistance = true;
                    Console.WriteLine("How far can this car drive on a single charge?");
                    try
                    {
                        newCar.DistancePerCharge = int.Parse(Console.ReadLine());
                        Console.Clear();
                    }
                    catch (Exception)
                    {
                        Console.Clear();
                        Console.WriteLine("Invalid selection. \nPress any key to continue...");
                        Console.ReadKey();
                        Console.Clear();
                        chooseDistance = false;
                    }
                }
                while (chooseChanges == false)
                {
                    chooseChanges = true;

                    Console.WriteLine("Please review the information for the new car\n");
                    newCar.PrintProps();
                    Console.WriteLine("\nDo you want to make any changes to this car?(y/n)");
                    string changesAnswer = Console.ReadLine().ToLower();

                    switch (changesAnswer)
                    {
                    case "y":
                        makeChanges = true;
                        break;

                    case "n":
                        addNewCar = true;
                        break;

                    default:
                        Console.Clear();
                        Console.WriteLine("Invalid selection. \nPress any key to continue...");
                        Console.ReadKey();
                        Console.Clear();
                        chooseChanges = false;
                        break;
                    }
                }
                Console.Clear();
                while (makeChanges == true)
                {
                    makeChanges = false;
                    Console.WriteLine($"What property would you like to change? Or select 6 to add the new car.\n");
                    newCar.PrintProps();
                    Console.WriteLine("7. Continue");
                    string propertyAnswer = Console.ReadLine().ToLower();
                    switch (propertyAnswer)
                    {
                    case "1":
                        chooseMake = false;
                        Console.Clear();
                        break;

                    case "2":
                        chooseModel = false;
                        Console.Clear();
                        break;

                    case "3":
                        chooseYear = false;
                        Console.Clear();
                        break;

                    case "4":
                        chooseCTD = false;
                        Console.Clear();
                        break;

                    case "5":
                        chooseMPG = false;
                        Console.Clear();
                        break;

                    case "6":
                        chooseDistance = false;
                        Console.Clear();
                        break;

                    case "7":
                        addNewCar = true;
                        Console.Clear();
                        break;

                    default:
                        Console.Clear();
                        Console.WriteLine("Invalid selection. \nPress any key to continue...");
                        Console.ReadKey();
                        Console.Clear();
                        makeChanges = true;
                        break;
                    }
                }
            }
            if (addNewCar == true)
            {
                _cars.AddCarToDirectory(newCar);
                Console.Clear();
                Console.WriteLine($"You have successfully added the {newCar.YearMakeModel}.");
                Console.WriteLine("Press any key to return to menu...");
                Console.ReadKey();
                Console.Clear();
            }
        }
        public void UpdateHybridCar()
        {
            Console.Clear();
            ListAllHybridCars();
            Console.WriteLine("Please enter the year make and model of the car to update(yyyy make model)");
            string oldcarToUpdate = Console.ReadLine();
            var    carToUpdate    = new HybridCar();

            carToUpdate = _cars.GetHybridCarByTitle(oldcarToUpdate);
            Console.Clear();
            bool makeChanges = true;

            while (makeChanges == true && carToUpdate != null)
            {
                makeChanges = false;
                Console.WriteLine($"What property would you like to change? Or select 7 to cancel.\n");
                carToUpdate.PrintProps();
                Console.WriteLine("7. Cancel");
                string propertyAnswer = Console.ReadLine().ToLower();
                Console.Clear();
                switch (propertyAnswer)
                {
                case "1":
                    Console.WriteLine("Enter a new make");
                    carToUpdate.Make = Console.ReadLine();
                    Console.Clear();
                    Console.WriteLine($"Make is now {carToUpdate.Make}\n");
                    Console.WriteLine("Press any key to return to menu...");
                    Console.ReadKey();
                    Console.Clear();
                    break;

                case "2":
                    Console.WriteLine("Enter a model");
                    carToUpdate.Model = Console.ReadLine();
                    Console.Clear();
                    Console.WriteLine($"Model is now {carToUpdate.Model}\n");
                    Console.WriteLine("Press any key to return to menu...");
                    Console.ReadKey();
                    Console.Clear();
                    break;

                case "3":
                    Console.WriteLine("Enter a year");
                    carToUpdate.Year = Console.ReadLine();
                    Console.Clear();
                    Console.WriteLine($"Year is now {carToUpdate.Year}\n");
                    Console.WriteLine("Press any key to return to menu...");
                    Console.ReadKey();
                    Console.Clear();
                    break;

                case "4":
                    Console.WriteLine("Enter a CostToDrive");
                    try
                    {
                        carToUpdate.CostToDrivePerYear = int.Parse(Console.ReadLine());
                        Console.Clear();
                        Console.WriteLine($"CostToDrive is now {carToUpdate.CostToDrivePerYear}\n");
                        Console.WriteLine("Press any key to return to menu...");
                        Console.ReadKey();
                        Console.Clear();
                    }
                    catch (Exception)
                    {
                        Console.Clear();
                        Console.WriteLine("Invalid selection. \nPress any key to continue...");
                        makeChanges = true;
                        Console.ReadKey();
                        Console.Clear();
                    }
                    break;

                case "5":
                    Console.WriteLine("Enter a new MPG");
                    try
                    {
                        carToUpdate.DistancePerCharge = int.Parse(Console.ReadLine());
                        Console.Clear();
                        Console.WriteLine($"MPG is now {carToUpdate.MPG}\n");
                        Console.WriteLine("Press any key to return to menu...");
                        Console.ReadKey();
                        Console.Clear();
                    }
                    catch (Exception)
                    {
                        Console.Clear();
                        Console.WriteLine("Invalid selection. \nPress any key to continue...");
                        makeChanges = true;
                        Console.ReadKey();
                        Console.Clear();
                    }
                    break;

                case "6":
                    Console.WriteLine("Enter a DistancePerCharge");
                    try
                    {
                        carToUpdate.DistancePerCharge = int.Parse(Console.ReadLine());
                        Console.Clear();
                        Console.WriteLine($"MPG is now {carToUpdate.DistancePerCharge}\n");
                        Console.WriteLine("Press any key to return to menu...");
                        Console.ReadKey();
                        Console.Clear();
                    }
                    catch (Exception)
                    {
                        Console.Clear();
                        Console.WriteLine("Invalid selection. \nPress any key to continue...");
                        makeChanges = true;
                        Console.ReadKey();
                        Console.Clear();
                    }
                    break;

                case "7":
                    Console.Clear();
                    break;

                default:
                    Console.Clear();
                    Console.WriteLine("Invalid selection. \nPress any key to continue...");
                    Console.ReadKey();
                    Console.Clear();
                    makeChanges = true;
                    break;
                }
            }
            if (carToUpdate == null)
            {
                Console.Clear();
                Console.WriteLine("Could not find that car");
                Console.WriteLine("Press any key to return to menu...");
                Console.ReadKey();
                Console.Clear();
            }
        }
        public void UpdateHybridCar()
        {
            HybridCar hybridCar2 = new HybridCar("Lexus", "LC500h", DateTime.Parse("01-01-2017"), 168, 4.8, TimeSpan.Parse("9:00"), 250);

            hybridCarRepository.UpdateHybridCar("XC60 T8", hybridCar2);
        }
Пример #24
0
        public void AddCar()
        {
            //Method to create new car in the database
            bool looper = true;
            Car  car    = new Car();

            while (looper)
            {
                Console.Clear();
                KomodoLogo();
                Console.WriteLine("<<<<<<<< Adding Car >>>>>>>");
                Console.WriteLine("What Category is the car:");
                Console.WriteLine("1> Gar Car");
                Console.WriteLine("2> Hybrid Car");
                Console.WriteLine("3> Electric Car");
                bool   classTypeLoop = true;
                string carClassType  = "";

                while (classTypeLoop)
                {
                    carClassType = Console.ReadLine();
                    switch (carClassType)
                    {
                    case "1":
                        car           = new GasCar();
                        classTypeLoop = false;
                        carClassType  = "Gas Car";
                        break;

                    case "2":
                        car           = new HybridCar();
                        classTypeLoop = false;
                        carClassType  = "Hybrid Car";
                        break;

                    case "3":
                        car           = new ElectricCar();
                        classTypeLoop = false;
                        carClassType  = "Electric Car";
                        break;

                    default:
                        Console.WriteLine("Please enter a valid selection. (1,2,3)");
                        break;
                    }
                }
                Console.WriteLine("Enter Make:");
                car.Make = Console.ReadLine();
                Console.WriteLine("Enter Model:");
                car.Model = Console.ReadLine();
                Console.WriteLine("Enter Model Year:");
                car.Year = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Please Select Vehicle Type:");
                //Sedan = 1, SUV, PickupTruck, Coupe, SportsCar, Wagon, HatchBack, Convertible, Minivan
                Console.WriteLine("1> Sedan");
                Console.WriteLine("2> SUV");
                Console.WriteLine("3> Pickup Truck");
                Console.WriteLine("4> Coupe");
                Console.WriteLine("5> Sports Car");
                Console.WriteLine("6> Wagon");
                Console.WriteLine("7> Hatch Back");
                Console.WriteLine("8> Convertible");
                Console.WriteLine("9> Minivan");
                bool   vehicleTypeLoop = true;
                string vehicleType     = "";
                while (vehicleTypeLoop)
                {
                    vehicleType = Console.ReadLine();
                    if (vehicleType == "1" || vehicleType == "2" || vehicleType == "3" || vehicleType == "4" || vehicleType == "5" || vehicleType == "6" || vehicleType == "7" || vehicleType == "8" || vehicleType == "9")
                    {
                        vehicleTypeLoop = false;
                    }
                    else
                    {
                        Console.WriteLine("Please enter a valid selection. (1,2,3,4,5,6,7,8 or 9");
                    }
                }
                car.Type = (VehicleType)int.Parse(vehicleType);
                Console.WriteLine("Enter avg fuel range:");
                car.AvgRange = Convert.ToDouble(Console.ReadLine());
                //if (car is HybridCar || car is GasCar)
                //{
                //    Console.WriteLine("Enter combined average MPG");
                //    // code to set the avg mpg
                //}
                //if (car is HybridCar || car is ElectricCar)
                //{
                //    Console.WriteLine("Enter battery capacity(kWh):");
                //    //code to set battery capacity
                //}
                if (car is GasCar)
                {
                    Console.WriteLine("Enter combined average MPG:");
                    ((GasCar)car).AvgMPG = Convert.ToDouble(Console.ReadLine());
                }
                else if (car is ElectricCar)
                {
                    Console.WriteLine("Enter battery capacity (kWh):");
                    ((ElectricCar)car).BatteryCapacity = Convert.ToDouble(Console.ReadLine());
                    Console.WriteLine("Enter charge time (220v):");
                    ((ElectricCar)car).ChargeTime = Convert.ToDouble(Console.ReadLine());
                }
                else if (car is HybridCar)
                {
                    Console.WriteLine("Enter combined average MPG:");
                    ((HybridCar)car).AvgMPG = Convert.ToDouble(Console.ReadLine());
                    Console.WriteLine("Enter battery capacity (kWh):");
                    ((HybridCar)car).BatteryCapacity = Convert.ToDouble(Console.ReadLine());
                }
                Console.Clear();
                KomodoLogo();
                Console.WriteLine("<<<<<<<< Adding Car >>>>>>>");

                //Console.WriteLine($"Vehicle Type: {carClassType}");
                //Console.WriteLine($"Car Make: {car.Make}");
                //Console.WriteLine($"Car Model: {car.Model}");
                //Console.WriteLine($"Car class: {car.Type.ToString()}");
                //Console.WriteLine($"Average fuel range: {car.AvgRange} miles");
                //if (car is GasCar)
                //{
                //    Console.WriteLine($"Average combined MPG: {((GasCar)car).AvgMPG}");
                //}
                //else if (car is HybridCar)
                //{
                //    Console.WriteLine($"Average combined MPG: {((HybridCar)car).AvgMPG}");
                //    Console.WriteLine($"Battery capacity: {((HybridCar)car).BatteryCapacity}");
                //}
                //else if (car is ElectricCar)
                //{
                //    Console.WriteLine($"Average charge time (@ 220v): {((ElectricCar)car).ChargeTime}");
                //    Console.WriteLine($"Battery capacity: {((ElectricCar)car).BatteryCapacity}");
                //}
                DisplayCar(car);
                Console.WriteLine("Does all of this look correct? \nEnter Y to add this car. \nEnter N to start over entering this car.");
                string correct = Console.ReadLine();
                if (correct.ToLower() == "y")
                {
                    looper = false;
                }
            }
            bool wasAdded = _repo.AddCar(car);

            if (wasAdded == true)
            {
                Console.WriteLine("Your car was added to the database.");
                Console.WriteLine("Press any key to Continue.");
            }
            else
            {
                Console.WriteLine("Oops. Something went wrong. Your car was not added.  Please Try Again");
                Console.WriteLine("Press any key to continue.");
            }

            Console.ReadKey();
        }
Пример #25
0
        public void UpdateCar()
        {
            Console.Clear();
            KomodoLogo();
            Console.WriteLine("<<<<<<<< Update Car >>>>>>>");
            Console.WriteLine("Enter Make:");
            string make = Console.ReadLine();

            Console.WriteLine("Enter Model:");
            string model = Console.ReadLine();

            Console.WriteLine("Enter Year:");
            string year     = Console.ReadLine();
            string oldCarID = year.ToString() + make.ToLower() + model.ToLower();
            Car    oldCar   = _repo.GetCarByID(oldCarID);

            if (oldCar != null)
            {
                Console.Clear();
                KomodoLogo();
                Console.WriteLine("<<<<<<<< Update Car >>>>>>>");
                DisplayCar(oldCar);
                Console.WriteLine();
                Console.WriteLine("---------------------------");
                bool looper = true;
                Car  car    = new Car();
                while (looper)
                {
                    Console.WriteLine("<<<<<<<< Updating >>>>>>>");
                    //Set car type
                    if (oldCar is GasCar)
                    {
                        car = new GasCar();
                    }
                    if (oldCar is HybridCar)
                    {
                        car = new HybridCar();
                    }
                    if (oldCar is ElectricCar)
                    {
                        car = new ElectricCar();
                    }
                    Console.WriteLine("Enter Make:");
                    car.Make = Console.ReadLine();
                    Console.WriteLine("Enter Model:");
                    car.Model = Console.ReadLine();
                    Console.WriteLine("Enter Model Year:");
                    car.Year = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Please Select Vehicle Type:");
                    //Sedan = 1, SUV, PickupTruck, Coupe, SportsCar, Wagon, HatchBack, Convertible, Minivan
                    Console.WriteLine("1> Sedan");
                    Console.WriteLine("2> SUV");
                    Console.WriteLine("3> Pickup Truck");
                    Console.WriteLine("4> Coupe");
                    Console.WriteLine("5> Sports Car");
                    Console.WriteLine("6> Wagon");
                    Console.WriteLine("7> Hatch Back");
                    Console.WriteLine("8> Convertible");
                    Console.WriteLine("9> Minivan");
                    bool   vehicleTypeLoop = true;
                    string vehicleType     = "";
                    while (vehicleTypeLoop)
                    {
                        vehicleType = Console.ReadLine();
                        if (vehicleType == "1" || vehicleType == "2" || vehicleType == "3" || vehicleType == "4" || vehicleType == "5" || vehicleType == "6" || vehicleType == "7" || vehicleType == "8" || vehicleType == "9")
                        {
                            vehicleTypeLoop = false;
                        }
                        else
                        {
                            Console.WriteLine("Please enter a valid selection. (1,2,3,4,5,6,7,8 or 9");
                        }
                    }
                    car.Type = (VehicleType)int.Parse(vehicleType);
                    Console.WriteLine("Enter avg fuel range:");
                    car.AvgRange = Convert.ToDouble(Console.ReadLine());
                    if (car is GasCar)
                    {
                        Console.WriteLine("Enter combined average MPG:");
                        ((GasCar)car).AvgMPG = Convert.ToDouble(Console.ReadLine());
                    }
                    else if (car is ElectricCar)
                    {
                        Console.WriteLine("Enter battery capacity (kWh):");
                        ((ElectricCar)car).BatteryCapacity = Convert.ToDouble(Console.ReadLine());
                        Console.WriteLine("Enter charge time (220v):");
                        ((ElectricCar)car).ChargeTime = Convert.ToDouble(Console.ReadLine());
                    }
                    else if (car is HybridCar)
                    {
                        Console.WriteLine("Enter combined average MPG:");
                        ((HybridCar)car).AvgMPG = Convert.ToDouble(Console.ReadLine());
                        Console.WriteLine("Enter battery capacity (kWh):");
                        ((HybridCar)car).BatteryCapacity = Convert.ToDouble(Console.ReadLine());
                    }
                    Console.Clear();
                    KomodoLogo();
                    Console.WriteLine("<<<<<<< Updating Car >>>>>>>");
                    Console.WriteLine("     <<    Old Car   >>");
                    DisplayCar(oldCar);
                    Console.WriteLine();
                    Console.WriteLine("     <<    New Car   >>");
                    DisplayCar(car);
                    Console.WriteLine("Does all of this look correct? \nEnter Y to add this car. \nEnter N to start over entering this car.");
                    string correct = Console.ReadLine();
                    if (correct.ToLower() == "y")
                    {
                        looper = false;
                    }
                }
                bool wasUpdated = _repo.UpdateExistingCar(oldCarID, car);
                if (wasUpdated == true)
                {
                    Console.WriteLine("Your car was update in the database.");
                    Console.WriteLine("Press any key to Continue.");
                }
                else
                {
                    Console.WriteLine("Oops. Something went wrong. Your car was not Updated.  Please Try Again");
                    Console.WriteLine("Press any key to continue.");
                }
            }
            else
            {
                Console.WriteLine("Car not found. \nPress any key to return to main menu.");
            }
            Console.ReadKey();
        }
Пример #26
0
 public HybridCar Delete(HybridCar hybridCar)
 {
     throw new NotImplementedException();
 }
Пример #27
0
        /// <summary>
        /// Событие по нажатию кнопки ввода
        /// </summary>
        private void EnterVehicle(object sender, EventArgs e)
        {
            try
            {
                label1.Text = "";
                if (comboBox1.SelectedIndex > -1)
                {
                    bool isDoNotWrite = false;
                    for (int j = 0; j <= dataGridView2.ColumnCount - 1; j++)
                    {
                        isDoNotWrite = dataGridView2.Rows[0].Cells[j].Value == null;
                    }
                    if (!isDoNotWrite)
                    {
                        Func <double, bool> doublefunc = (val) =>
                        {
                            return(val > 0);
                        };
                        var consumption = GetValidValue(doublefunc, double.TryParse,
                                                        "Enter consumption(>0)",
                                                        Convert.ToString(dataGridView2[1, 0].Value), label1);

                        var speed = GetValidValue(doublefunc, double.TryParse,
                                                  "Enter speed(>0)",
                                                  Convert.ToString(dataGridView2[2, 0].Value), label1);

                        switch ((string)comboBox1.SelectedItem)
                        {
                        case "Car":
                        {
                            if (speed == 0 || consumption == 0)
                            {
                                return;
                            }

                            Vehicle = new Car(VehicleType.Car,
                                              Convert.ToString(dataGridView2[0, 0].Value),
                                              consumption, speed);
                            this.Close();
                            break;
                        }

                        case "HybridCar":
                        {
                            Func <double, bool> doublefuncEconomy = (val) =>
                            {
                                return(val < 1 && val > 0);
                            };
                            double economy =
                                GetValidValue(doublefuncEconomy,
                                              double.TryParse,
                                              "Wrong economy(0-1)",
                                              Convert.ToString(dataGridView2[3, 0].Value),
                                              label1);
                            if (speed == 0 || consumption == 0 || economy == 0)
                            {
                                return;
                            }
                            HybridCar hybrid =
                                new HybridCar(VehicleType.HybridCar,
                                              Convert.ToString(dataGridView2[0, 0].Value),
                                              consumption, speed, economy);
                            Vehicle = hybrid;
                            this.Close();
                            break;
                        }

                        case "Helicopter":
                        {
                            Func <int, bool> funcEngines = (val) =>
                            {
                                return(val >= 1);
                            };
                            int numOfEngines =
                                GetValidValue(funcEngines, int.TryParse,
                                              "Incorrect number of engines (>1)",
                                              Convert.ToString(dataGridView2[3, 0].Value),
                                              label1);
                            if (speed == 0 || consumption == 0 || numOfEngines == 0)
                            {
                                return;
                            }
                            Helicopter helicopter =
                                new Helicopter(VehicleType.Helicopter,
                                               Convert.ToString(dataGridView2[0, 0].Value),
                                               consumption, speed, numOfEngines);
                            Vehicle = helicopter;
                            this.Close();
                            break;
                        }

                        default:
                        {
                            label1.Text = "Something wrong with data input";
                            break;
                        }
                        }
                    }
                    else
                    {
                        label1.Text = "Something wrong with data input";
                    }
                }
            }
            catch
            {
                MessageBox.Show("Something wrong");
            }
        }
Пример #28
0
        static void Main(string[] args)
        {
            Console.WriteLine("---Klasa abstrakcyjna i polimorfizm---\n");

            Student s1 = new DomesticStudent("Jacek", "Kowalczyk", "Poland", "s1345", 15, 0);
            Student s2 = new ForeignStudent("Robert", "Muller", "Germany", "s1077");

            Console.WriteLine(s1.CalculateYearlyTuitionFee());
            Console.WriteLine(s2.CalculateYearlyTuitionFee());

            Console.WriteLine("\n---Dziedziczenie overlapping---\n");

            EventParticipant t1 = new EventParticipant("Tomasz", "Kowalski", "Poland", new DateTime(2000, 11, 30), new List <ParticipationType> {
                ParticipationType.Player
            }, null, "21");
            EventParticipant t2 = new EventParticipant("Grzegorz", "Lewandowski", "Poland", new DateTime(1976, 01, 06), new List <ParticipationType> {
                ParticipationType.Referee
            }, "S982EV", null);
            EventParticipant t3 = new EventParticipant("Paweł", "Nowak", "Poland", new DateTime(1988, 06, 14), new List <ParticipationType> {
                ParticipationType.Player, ParticipationType.Referee
            }, "A317B", "33");

            Console.WriteLine(t1.isPlayer());
            Console.WriteLine(t1.isReferee());
            Console.WriteLine(t1.ToString());

            Console.WriteLine(t2.isPlayer());
            Console.WriteLine(t2.isReferee());
            Console.WriteLine(t2.ToString());

            Console.WriteLine(t3.isPlayer());
            Console.WriteLine(t3.isReferee());
            Console.WriteLine(t3.ToString());

            Console.WriteLine("\n---Dziedziczenie dynamiczne---\n");

            Account acc1 = new AccountPremium("Thomas", new DateTime(2020, 05, 11), "England", new MailAddress("*****@*****.**"), new DateTime(2020, 05, 20), SubscriptionType.Silver);
            Account acc2 = new AccountNormal("Janeq", new DateTime(2018, 09, 29), "Poland", new MailAddress("*****@*****.**"));

            Console.WriteLine(acc1.ToString());
            Console.WriteLine(acc2.ToString());

            acc1 = new AccountNormal(acc1);
            acc2 = new AccountPremium(acc2, new DateTime(2019, 10, 24), SubscriptionType.Diamond);

            Console.WriteLine(acc1.ToString());
            Console.WriteLine(acc2.ToString());

            acc1 = new AccountPremium(acc1, new DateTime(2020, 05, 20), SubscriptionType.Silver);

            Console.WriteLine(acc1.ToString());

            Console.WriteLine("\n---Wielodziedziczenie---\n");

            Car c1 = new CombustionCar("Lamborghini Huracan", 610, 2016, 11.0, 83);
            Car c2 = new ElectricCar("BMW i3", 170, 2013, 260.0, 13.1);
            Car c3 = new HybridCar("Toyota C-HR", 122, 2017, 3.6, 43, 50.0, 2.0);

            Console.WriteLine(c1.CalculateNeededUnit(250.00));
            Console.WriteLine(c2.CalculateNeededUnit(250.00));
            Console.WriteLine(c3.CalculateNeededUnit(250.00) + "\n");

            Console.WriteLine(c3.ToString());

            Console.WriteLine("\n---Wieloaspektowe---\n");

            Device d1 = new Device("JBL", "Flip 5", "Blue", 12);
            Device d2 = new Device("Steelseries", "Arctis 5", "Black", 3.0);

            Mouse    m1 = new Mouse("Logitech", "G PRO", "Black", 7, 25600);
            Keyboard k1 = new Keyboard("Razer", "Huntsman", "Black", SwitchType.Mechanical, true);

            Console.WriteLine(d1.GetConnection());
            Console.WriteLine(d2.GetConnection() + "\n");

            Console.WriteLine(d1.ToString());
            Console.WriteLine(d2.ToString());
            Console.WriteLine(m1.ToString());
            Console.WriteLine(k1.ToString());
        }
        public void AddNewHybridCar()
        {
            HybridCar hybridCar1 = new HybridCar("Volvo", "XC60 T8", DateTime.Parse("01-01-2017"), 124, 5.7, TimeSpan.Parse("3:30"), 600);

            hybridCarRepository.AddHybridCar(hybridCar1);
        }