/*Function that takes in: * b. The Car to calculate the tax from. * then calls the tax function from the TaxCalculator class to calculate the tax for the car.*/ private void calcTax(Car taxCar) { try { /*If the car emits CO2 then we will calculate the tax cost when the item is clicked.*/ if (taxCar.CO2gramsPerKilometer != null && taxCar.CO2gramsPerKilometer != 0) { TaxCalculator tax = new TaxCalculator(); float? taxCost = tax.CalculateTax(taxCar); } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
/*Function that takes in: * a. the classes Listed Object. * b. the element from the ListBox that the user has selected.*/ public Listed ModelSelected(int element, Listed carList) { Car car = null; /*If the user has selected a legitimate element that's not null.*/ if (element > -1) { /*selecting the car at the selected element.*/ car = carList.CurrentCars.ElementAt(element); /*If the car we just got is not null then we will calculate the cost.*/ if (car != null) { TaxCalculator tax = new TaxCalculator(); float? taxCost = tax.CalculateTax(car); } } /*setting the carLists selected car to either be the car at the element selected * or if the element selected is invalid then null.*/ carList.SelectedCar = car; /*Returns the car list after we've seleted the chosen car.*/ return(carList); }
public Overview() { InitializeComponent(); LoadCar load = new LoadCar(); cars = load.Load(); car = load.LoadSelectedCar(); /*Calculating the tax for each of the cars in car.*/ try { foreach (Car theCar in cars) { if (theCar.CO2gramsPerKilometer != null && theCar.CO2gramsPerKilometer != 0) { TaxCalculator tax = new TaxCalculator(); float? taxCost = tax.CalculateTax(theCar); } } if (car.CO2gramsPerKilometer != null && car.CO2gramsPerKilometer != 0) { TaxCalculator tax = new TaxCalculator(); float? taxCost = tax.CalculateTax(car); } } catch (Exception e) { Console.WriteLine(e.ToString()); } string thisDirectory = Directory.GetCurrentDirectory().ToString(); string fileLoc = thisDirectory + @"\Images\LeafIcon.png"; pictureBox1.Image = Image.FromFile(fileLoc); pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; /*If the car is null that means that the user has not * yet selected a car to be there main car, in which case we will set the * first car in the array (if it exists) to be the selected car.*/ if (car == null) { /*Checking if the user has added any cars to the list before * if they have we will set the first of these cars to be the selected cars, else * we will display the user with an error message.*/ if (cars != null && cars.Count() > 0) { SaveCar save = new SaveCar(); save.selectedCar(0); //printer so we can print information about the car. CarPrinter printer = new CarPrinter(); string info = printer.carHeader(cars.ElementAt(0)); string details = printer.printcar(cars.ElementAt(0), measurementSystem); CarInfo.Text = info; CarDetails.Text = details; setImage(cars.ElementAt(0).Manufacturer); } /*Else we have no saved cars either so we will * display a messaage to the user saying we have no car.*/ else { setImage("error"); CarInfo.Text = "Error! Please go to Add Car and add your car/cars."; CarDetails.Text = "Error!"; } } //else a saved car does exist so use this instead. else { CarPrinter printer = new CarPrinter(); string info = printer.carHeader(car); string details = printer.printcar(car, measurementSystem); CarInfo.Text = info; CarDetails.Text = details; setImage(car.Manufacturer); } }