Ejemplo n.º 1
0
        public void AddCarCountShouldIncrease()
        {
            GasCar focusST = new GasCar("Ford Focus ST", 25);

            bool wasAdded = _repo.AddGasCarToDirectory(focusST);

            Assert.IsTrue(wasAdded);
        }
Ejemplo n.º 2
0
        public void SeedGas()
        {
            GasCar f150     = new GasCar("Ford F-150", 16);
            GasCar fiestaST = new GasCar("Ford Fiesta ST", 25);

            _repo.AddGasCarToDirectory(f150);
            _repo.AddGasCarToDirectory(fiestaST);
        }
Ejemplo n.º 3
0
        public void GetGasByNameShouldGetGas()
        {
            GasCar focusST = new GasCar("Ford Focus ST", 25);

            _repo.AddGasCarToDirectory(focusST);
            GasCar test = _repo.GetGasByName("Ford Focus ST");

            Assert.AreEqual(focusST, test);
        }
        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);
        }
Ejemplo n.º 6
0
        public void AddCarToListTest()
        {
            GasCar carTwo = new GasCar("Nissan", "Versa", 32.5d, 140000.00m, 14);

            _carsList.AddCarToList(carTwo);

            int expected = 2;
            int actual   = _carsList.GetCarsList().Count;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 7
0
        public void UpdateCarShouldUpdate()
        {
            GasCar newCar = new GasCar("Ford F-150", 10);

            _repo.UpdateGasByName("Ford F-150", newCar);

            int expected = 10;
            int actual   = _repo.GetGasByName("Ford F-150").GasMileage;

            Assert.AreEqual(expected, actual);
        }
        public void GetAllCars_ShouldReturnCorrectCollection() //Read
        {
            //Arrange
            GasCar   car  = new GasCar("ford", "mustang", 2020);
            Car_Repo repo = new Car_Repo();

            repo.AddCar(car);
            //Act
            List <Car> localCars = repo.GetAllCars();
            bool       hasCar    = localCars.Contains(car);

            //Assert
            Assert.IsTrue(hasCar);
        }
        public void UpdateExistingCar_ShouldReturnTrue() //Update a car
        {
            //Arrange
            GasCar   car  = new GasCar("ford", "mustang", 2020);
            GasCar   car2 = new GasCar("toyota", "camry", 2019, VehicleType.Sedan, 624, 32);
            Car_Repo repo = new Car_Repo();

            repo.AddCar(car);
            string id = "2020fordmustang";

            //Act
            bool UpdateResult = repo.UpdateExistingCar(id, car2);

            //Assert
            Assert.IsTrue(UpdateResult);
        }
Ejemplo n.º 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 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);
        }
        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 DeleteCar()//Delete a car from repo
        {
            //Arrange
            GasCar   car  = new GasCar("ford", "mustang", 2020);
            Car_Repo repo = new Car_Repo();

            repo.AddCar(car);
            string id = "2020fordmustang";


            //Act
            Car  oldCar       = repo.GetCarByID(id);
            bool removeResult = repo.DeleteCar(oldCar);

            //Assert
            Assert.IsTrue(removeResult);
        }
        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);
        }
        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);
        }
        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);
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 20
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();
        }
        private IGasCar GasCarSetup(bool isUpdating)
        {
            GasCar newGasCar = new GasCar();

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

            return(newGasCar);
        }
        public void NewGasCar()
        {
            bool addNewCar     = false;
            bool chooseMake    = false;
            bool chooseModel   = false;
            bool chooseYear    = false;
            bool chooseCTD     = false;
            bool chooseMPG     = false;
            bool chooseChanges = false;
            bool makeChanges   = false;
            var  newCar        = new GasCar();

            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();
                        chooseMPG = 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("6. 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":
                        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();
            }
        }
Ejemplo n.º 23
0
 public GasCar Delete(GasCar gasCar)
 {
     throw new NotImplementedException();
 }
        public void UpdateGasCar()
        {
            Console.Clear();
            ListAllGasCars();
            Console.WriteLine("Please enter the year make and model of the car to update(yyyy make model)");
            string oldcarToUpdate = Console.ReadLine();
            var    carToUpdate    = new GasCar();

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

            while (makeChanges == true && carToUpdate != null)
            {
                makeChanges = false;
                Console.WriteLine($"What property would you like to change? Or select 6 to cancel.\n");
                carToUpdate.PrintProps();
                Console.WriteLine("6. 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 MPG");
                    try
                    {
                        carToUpdate.MPG = 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...");
                        Console.ReadKey();
                        Console.Clear();
                        makeChanges = true;
                    }
                    break;

                case "6":
                    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.WriteLine("Could not find that car");
                Console.WriteLine("Press any key to return to menu...");
                Console.ReadKey();
                Console.Clear();
            }
        }
        public void UpdateGasCar()
        {
            GasCar newGasCar = new GasCar("Honda", "Clarity Gas", DateTime.Parse("1/1/2018"), 114, 9, TimeSpan.Parse("9:5"), 89);

            gasCarRepository.UpdateGasCar("e-tron 55", newGasCar);
        }
Ejemplo n.º 26
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();
        }
Ejemplo n.º 27
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();
        }
        public void AddNewGasCar()
        {
            GasCar gasCar1 = new GasCar("Toyota", "Prius Eco", DateTime.Parse("01-01-2020"), 124, 9.9, TimeSpan.Parse("0"), 269);

            gasCarRepository.AddGasCar(gasCar1);
        }