Showing posts with label Object. Show all posts
Showing posts with label Object. Show all posts

Thursday, May 21, 2009

Car Array, Finding the cars by max and min seats available



private void FindCarButton_Click(object sender, EventArgs e)
{
//Initialise Cars
Car[] cars = rental.GetAllCars();

//Reset listbox
CarsListBox.Items.Clear();

int iMin = int.Parse(MinTextBox.Text);
int iMax = int.Parse(MaxTextBox.Text);
Car[] carsfound = rental.GetCarsByPassengers(iMax, iMin);

for (int i = 0; i < carsfound.Length; i++)
{
if (carsfound[i] != null)
CarsListBox.Items.Add(carsfound[i].Model);
}
}




//method #2 - GetCarsByMaxPassengers
public Car[] GetCarsByPassengers(int max, int min)
{
Car[] cars = new Car[15];
for (int i = 0; i < carArray.Length ; i++)
{
if ((carArray[i].NoPassengers >= min) && (carArray[i].NoPassengers + 1 <= max))
{
cars[i] = carArray[i];
}
}
return cars;
}