Esempio n. 1
0
        private void UpdateCar()
        {
            int listCountCheck = carRepo.GetAllCars().Count;

            Console.WriteLine("\nEnter the car to update:");
            string name = Console.ReadLine();

            // see if the car exists
            if (carRepo.GetOneCar(name) != null)
            {
                Console.WriteLine("\nEnter the new car name:");
                string newName  = Console.ReadLine();
                int    numDoors = InputIntHelper("\nEnter the new number of doors on this car:", "\nEnter the number of doors as a whole number");
                double price    = InputDoubleHelper("\nEnter the new vehicle price(#####.##)", "\nEnter the vehicle price(#####.##) without $");
                Console.WriteLine("\nEnter the new car type (1. Gas, 2. Hybred, 3. Electric)");
                string type = Console.ReadLine();
                switch (type.ToLower())
                {
                case "1":
                {
                    double MPG          = InputDoubleHelper("\nEnter the Miles Per Gallon (MPG) for car:", "\nEnter the Miles Per Gallon (MPG) as a whole number");
                    int    fuelTankSize = InputIntHelper("\nEnter the fuel capacity for car in gallons:", "\nEnter the fuel capacity as a whole number");
                    carRepo.UpdateCar(name, new Gas(newName, numDoors, price, MPG, fuelTankSize));
                    break;
                }

                case "2":
                {
                    double MPG   = InputDoubleHelper("\nEnter the new Miles Per Gallon (MPG) for car:", "\nEnter the Miles Per Gallon (MPG) as a whole number");
                    int    power = InputIntHelper("\nEnter the new horsepower for car:", "\nEnter the horsepower as a whole number");
                    carRepo.UpdateCar(name, new Hybred(newName, numDoors, price, MPG, power));
                    break;
                }

                case "3":
                {
                    int range = InputIntHelper("\nEnter the range for car:", "\nEnter the range as a whole number");
                    carRepo.UpdateCar(name, new Electric(name, numDoors, price, range));
                    break;
                }

                default:
                {
                    Console.WriteLine("\nVehicles are limited to these three types only");
                    break;
                }
                }
            }
            else
            {
                Console.WriteLine("\nNo car with that name has been entered.");
            }
        }
Esempio n. 2
0
        public void TestUpdate()
        {
            testCarRepo.AddCar(new Hybred("Prius", 3, 35900.00, 45, 120));
            testCarRepo.AddCar(new Electric("Volt", 5, 45500.00, 400));
            testCarRepo.AddCar(new Electric("Zinger", 5, 45500.00, 400));
            testCarRepo.AddCar(new Electric("Magic", 5, 45500.00, 400));
            Gas updateTest = new Gas("Charger", 4, 32500.00, 25.8, 20);

            Assert.IsTrue(testCarRepo.UpdateCar("Prius", updateTest));
        }
Esempio n. 3
0
        // Update existing cars
        private void UpdateExistingCars()
        {
            ViewAllCars();
            Console.WriteLine("Enter the car you want to update:");
            string oldCar = Console.ReadLine();
            Car    newCar = new Car();

            Console.WriteLine("Enter the make of the car you want to add:");
            newCar.CarMake = Console.ReadLine();

            Console.WriteLine("Enter the model of the car you want to add:");
            newCar.CarModel = Console.ReadLine();

            Console.WriteLine("Enter the description for the car you are adding:");
            newCar.Description = Console.ReadLine();

            Console.WriteLine("Enter the number for which engine type the car has:\n" +
                              "1.Gas\n" +
                              "2.Electric\n" +
                              "3.Hybrid");

            string engineAsString = Console.ReadLine();
            int    engineAsInt    = int.Parse(engineAsString);

            newCar.EngineType = (EngineType)engineAsInt;
            bool wasUpdated = _contentRepo.UpdateCar(oldCar, newCar);

            if (wasUpdated)
            {
                Console.WriteLine("Car was successfully updated!");
            }
            else
            {
                Console.WriteLine("Car was not updated!");
            }
        }