Ejemplo n.º 1
0
        /// <summary>
        /// Refuels a vehicle which is regular (not electric)
        /// </summary>
        private void refuelVehicle()
        {
            System.Console.Clear();
            System.Console.WriteLine(@"
/*===================================================================*\
  -------------------------Refuel Vehicle----------------------------
\*===================================================================*/");
            string       userInputLicenseNumber = getLicenseNumberFromUser();
            CustomerFile file = findFileByVehicleLicenseNumber(userInputLicenseNumber);

            if (file != null && file.Vehicle is RegularVehicle)
            {
                RegularVehicle.eFuelType inputFuelType = getFuelTypeFromUser();
                float fuelQuantity;

                do
                {
                    fuelQuantity = getFuelQuantityFromUser();
                    try
                    {
                        ((RegularVehicle)file.Vehicle).Refuel(fuelQuantity, inputFuelType);
                    }
                    catch (ValueOutOfRangeException e)
                    {
                        System.Console.WriteLine(e.Message);
                        fuelQuantity = -1;
                    }
                } while (fuelQuantity == -1);

                printSuccessMsg();
            }
        }
Ejemplo n.º 2
0
        private void addVehicleModelName(CustomerFile i_CustomerFile)
        {
            System.Console.Write("Enter vehicle's model name: ");
            string vehicleModelName = System.Console.ReadLine();

            i_CustomerFile.Vehicle.ModelName = vehicleModelName;
        }
Ejemplo n.º 3
0
        private void chargeVehicle()
        {
            System.Console.Clear();
            System.Console.WriteLine(@"
/*===================================================================*\
  -------------------------Charge Vehicle----------------------------
\*===================================================================*/");
            string       userInputLicenseNumber = getLicenseNumberFromUser();
            CustomerFile file = findFileByVehicleLicenseNumber(userInputLicenseNumber);

            if (file != null && file.Vehicle is ElectricVehicle)
            {
                float batteryChargeInMinFromUser;

                do
                {
                    batteryChargeInMinFromUser = getBatteryChargeFromUser();
                    try
                    {
                        ((ElectricVehicle)file.Vehicle).chargeBattery(batteryChargeInMinFromUser);
                    }
                    catch (ValueOutOfRangeException e)
                    {
                        System.Console.WriteLine(e.Message);
                        batteryChargeInMinFromUser = -1;
                    }
                } while (batteryChargeInMinFromUser == -1);

                printSuccessMsg();
            }
        }
Ejemplo n.º 4
0
        private static void printFullInformationForFile(CustomerFile file)
        {
            System.Console.Write(string.Format(@"
License Number: {0}
Model: {1}
Owner: {2}
Vehicle Status: {3}
Tyres: 
",
                                               file.Vehicle.LicenseNumber,
                                               file.Vehicle.ModelName,
                                               file.Name,
                                               file.Status));
            foreach (Tyre tyre in file.Vehicle.Tyres)
            {
                System.Console.WriteLine(string.Format("Brand: {1} Pressure: {2}{0}", Environment.NewLine, tyre.BrandName, tyre.AirPressure));
            }

            if (file.Vehicle is RegularVehicle)
            {
                System.Console.WriteLine(string.Format("Fuel type: {1}{0}Fuel percentange: {2:0.00}%{0}Tank Max capacity: {3}", Environment.NewLine,
                                                       ((RegularVehicle)file.Vehicle).FuelType, ((RegularVehicle)file.Vehicle).FuelPercentage, ((RegularVehicle)file.Vehicle).FuelMaxCapacity));
            }
            else if (file.Vehicle is ElectricVehicle)
            {
                System.Console.WriteLine(string.Format("Charge left: {1}{0}Max charge: {2}", Environment.NewLine,
                                                       ((ElectricVehicle)file.Vehicle).HoursOfChargeLeft, ((ElectricVehicle)file.Vehicle).MaxBatteryCharge));
            }
        }
Ejemplo n.º 5
0
        private static void addCustomerDetailsToFile(out CustomerFile o_NewCustomerFile)
        {
            System.Console.Write("Enter customer name: ");
            string customerName = System.Console.ReadLine();

            System.Console.Write("Enter customer phone number: ");
            string customerPhoneNumber = System.Console.ReadLine();

            o_NewCustomerFile = new CustomerFile(customerName, customerPhoneNumber);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Inflates vehicle tyres to maximum
        /// </summary>
        private void inflateVehicleTyres()
        {
            string       licenseNumber = getLicenseNumberFromUser();
            CustomerFile file          = findFileByVehicleLicenseNumber(licenseNumber);

            if (file != null)
            {
                foreach (Tyre tyre in file.Vehicle.Tyres)
                {
                    tyre.AirPressure = tyre.MaxPressure;
                }
                printSuccessMsg();
            }
        }
Ejemplo n.º 7
0
        private void showVehicleFullInformation()
        {
            System.Console.Clear();
            System.Console.WriteLine(@"
/*===================================================================*\
  ---------------Show Vehicle Full Information-----------------------
\*===================================================================*/");
            string       userInputLicense = getLicenseNumberFromUser();
            CustomerFile file             = findFileByVehicleLicenseNumber(userInputLicense);

            if (file != null)
            {
                printFullInformationForFile(file);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Finds a file by searching vehicles numbers
        /// </summary>
        /// <param name="licenseNumber"></param>
        /// <returns></returns>
        private CustomerFile findFileByVehicleLicenseNumber(string i_LicenseNumber)
        {
            CustomerFile foundFile = null;

            foreach (CustomerFile file in m_CustomersFiles)
            {
                if (file.Vehicle.LicenseNumber != null && file.Vehicle.LicenseNumber.Equals(i_LicenseNumber))
                {
                    foundFile = file;
                    break;
                }
            }

            return(foundFile);
        }
Ejemplo n.º 9
0
 private void getPowerSourceInformation(CustomerFile io_CustomerFile)
 {
     if (io_CustomerFile.Vehicle is RegularVehicle)
     {
         RegularVehicle.eFuelType fuelType = getFuelTypeFromUser();
         (io_CustomerFile.Vehicle as RegularVehicle).FuelType = fuelType;
         float fuelQuantityFromUser = getFuelQuantityFromUser();
         (io_CustomerFile.Vehicle as RegularVehicle).FuelQuantity = fuelQuantityFromUser;
     }
     else
     {
         // Add special options for electric vehicles
         float chargeLeftInput = getBatteryChargeLeftFromUser();
         (io_CustomerFile.Vehicle as ElectricVehicle).HoursOfChargeLeft = chargeLeftInput;
     }
 }
Ejemplo n.º 10
0
        private void changeVehicleStatus()
        {
            System.Console.Clear();
            System.Console.WriteLine(@"
/*===================================================================*\
  ---------------------Change Vehicle Status-------------------------
\*===================================================================*/");
            string       licenseNumber = getLicenseNumberFromUser();
            CustomerFile file          = findFileByVehicleLicenseNumber(licenseNumber);

            if (file != null)
            {
                updateVehicleStatus(file, getVehicleStatusFromUser());
                printSuccessMsg();
            }
            else
            {
                System.Console.WriteLine("Sorry!, that vehicle is not in the garage");
            }
        }
Ejemplo n.º 11
0
        private void updateTyresForCustomerVehicle(CustomerFile newCustomerFile)
        {
            string tyresBrandName = getBrandNameFromUser();

            try
            {
                System.Console.Write("Enter tyre max pressure: ");
                float tyresMaxPressureByVendor = getPressuresFromUser();
                System.Console.Write("Enter tyre current pressure: ");
                float tyreCurrentAirPressure = getPressuresFromUser();
                foreach (Tyre tyre in newCustomerFile.Vehicle.Tyres)
                {
                    tyre.BrandName   = tyresBrandName;
                    tyre.MaxPressure = tyresMaxPressureByVendor;
                    tyre.AirPressure = tyreCurrentAirPressure;
                }
            }
            catch (FormatException e)
            {
                System.Console.WriteLine(e.Data);
            }
        }
Ejemplo n.º 12
0
        private static void addCustomerDetailsToFile(out CustomerFile o_NewCustomerFile)
        {
            System.Console.Write("Enter customer name: ");
            string customerName = System.Console.ReadLine();
            System.Console.Write("Enter customer phone number: ");
            string customerPhoneNumber = System.Console.ReadLine();

            o_NewCustomerFile = new CustomerFile(customerName, customerPhoneNumber);
        }
Ejemplo n.º 13
0
 private void addVehicleModelName(CustomerFile i_CustomerFile)
 {
     System.Console.Write("Enter vehicle's model name: ");
     string vehicleModelName = System.Console.ReadLine();
     i_CustomerFile.Vehicle.ModelName = vehicleModelName;
 }
Ejemplo n.º 14
0
 private void getPowerSourceInformation(CustomerFile io_CustomerFile)
 {
     if (io_CustomerFile.Vehicle is RegularVehicle)
     {
         RegularVehicle.eFuelType fuelType = getFuelTypeFromUser();
         (io_CustomerFile.Vehicle as RegularVehicle).FuelType = fuelType;
         float fuelQuantityFromUser = getFuelQuantityFromUser();
         (io_CustomerFile.Vehicle as RegularVehicle).FuelQuantity = fuelQuantityFromUser;
     }
     else
     {
         // Add special options for electric vehicles
         float chargeLeftInput = getBatteryChargeLeftFromUser();
         (io_CustomerFile.Vehicle as ElectricVehicle).HoursOfChargeLeft = chargeLeftInput;
     }
 }
Ejemplo n.º 15
0
 private void updateVehicleStatus(CustomerFile i_File, CustomerFile.eVehicleStatus i_Status)
 {
     i_File.Status = i_Status;
 }
Ejemplo n.º 16
0
        private static void printFullInformationForFile(CustomerFile file)
        {
            System.Console.Write(string.Format(@"
            License Number: {0}
            Model: {1}
            Owner: {2}
            Vehicle Status: {3}
            Tyres:
            ",
            file.Vehicle.LicenseNumber,
            file.Vehicle.ModelName,
            file.Name,
            file.Status));
            foreach (Tyre tyre in file.Vehicle.Tyres)
            {
                System.Console.WriteLine(string.Format("Brand: {1} Pressure: {2}{0}", Environment.NewLine, tyre.BrandName, tyre.AirPressure));
            }

            if (file.Vehicle is RegularVehicle)
            {
                System.Console.WriteLine(string.Format("Fuel type: {1}{0}Fuel percentange: {2:0.00}%{0}Tank Max capacity: {3}", Environment.NewLine,
                    ((RegularVehicle)file.Vehicle).FuelType, ((RegularVehicle)file.Vehicle).FuelPercentage, ((RegularVehicle)file.Vehicle).FuelMaxCapacity));
            }
            else if (file.Vehicle is ElectricVehicle)
            {
                System.Console.WriteLine(string.Format("Charge left: {1}{0}Max charge: {2}", Environment.NewLine,
                    ((ElectricVehicle)file.Vehicle).HoursOfChargeLeft, ((ElectricVehicle)file.Vehicle).MaxBatteryCharge));
            }
        }
Ejemplo n.º 17
0
 private void showAllVehiclesInGarageOfStatus(CustomerFile.eVehicleStatus i_Status)
 {
     foreach (CustomerFile file in m_CustomersFiles)
     {
         if (file.Status.Equals(i_Status))
         {
             file.PrintFileInformation();
         }
     }
 }
Ejemplo n.º 18
0
        private void addNewVehicle()
        {
            string       inputLicenseString = getLicenseNumberFromUser();
            CustomerFile newCustomerFile    = findFileByVehicleLicenseNumber(inputLicenseString);

            // If the vehicle is in the garage already, update status
            if (newCustomerFile != null)
            {
                updateVehicleStatus(newCustomerFile, CustomerFile.eVehicleStatus.Unfixed);
                System.Console.WriteLine("This vehicle is already in the Garage.");
                return;
            }
            else
            {
                addCustomerDetailsToFile(out newCustomerFile);

                VehicleFactory.eVehicleTypes vehicleTypeInput;
                while (true)
                {
                    try
                    {
                        vehicleTypeInput = getVehicleTypeFromUser();
                    }
                    catch (FormatException e)
                    {
                        System.Console.WriteLine(e.Message);
                        continue;
                    }
                    break;
                }

                newCustomerFile.Vehicle = VehicleFactory.createNewVehicle(vehicleTypeInput);

                addVehicleModelName(newCustomerFile);

                // Adds the license number to the vehicle
                newCustomerFile.Vehicle.LicenseNumber = inputLicenseString;

                // Get power information (fuel or electrical source)
                getPowerSourceInformation(newCustomerFile);

                // Update tyres pressure
                System.Console.WriteLine("Update tyres details - ");
                updateTyresForCustomerVehicle(newCustomerFile);


                // Add other special properties
                int  propertieIndex = 0;
                bool inputPropertieSuccess;
                foreach (string propertie in newCustomerFile.Vehicle.Properties)
                {
                    inputPropertieSuccess = false;
                    do
                    {
                        System.Console.Write(propertie);
                        string userInput = System.Console.ReadLine();
                        inputPropertieSuccess = newCustomerFile.Vehicle.TrySetVehicleProperties(userInput, propertieIndex);
                    } while (inputPropertieSuccess == false);
                    propertieIndex++;
                }

                // Adds the new file
                CustomerFiles.Add(newCustomerFile);
            }
        }
Ejemplo n.º 19
0
 private void updateVehicleStatus(CustomerFile i_File, CustomerFile.eVehicleStatus i_Status)
 {
     i_File.Status = i_Status;
 }
Ejemplo n.º 20
0
 private void updateTyresForCustomerVehicle(CustomerFile newCustomerFile)
 {
     string tyresBrandName = getBrandNameFromUser();
     try
     {
         System.Console.Write("Enter tyre max pressure: ");
         float tyresMaxPressureByVendor = getPressuresFromUser();
         System.Console.Write("Enter tyre current pressure: ");
         float tyreCurrentAirPressure = getPressuresFromUser();
         foreach (Tyre tyre in newCustomerFile.Vehicle.Tyres)
         {
             tyre.BrandName = tyresBrandName;
             tyre.MaxPressure = tyresMaxPressureByVendor;
             tyre.AirPressure = tyreCurrentAirPressure;
         }
     }
     catch (FormatException e)
     {
         System.Console.WriteLine(e.Data);
     }
 }