public void add_passenger() { for (int i = 0; i < newPassengersGroup.Length; i++) { if (newPassengersGroup[i] == null) { // Random randomizer = new Random(); int age = randomizer.Next(13, 89); int salary = randomizer.Next(15000, 80000); string[] genders = { "man", "woman" }; string gender = genders[randomizer.Next(0, genders.Length)]; System.Console.WriteLine("there is an empty seat"); newPassengersGroup[i] = new passengers(age, gender, salary); System.Console.WriteLine("Passengers age: {0} ", newPassengersGroup[i].age); System.Console.WriteLine("Passenger gender: {0} ", newPassengersGroup[i].gender); if (passengersCount == 0) { passengersCount = 1; } else { passengersCount++; } break; } } if (newPassengersGroup[newPassengersGroup.Length - 1] != null) { System.Console.WriteLine("Sorry there are not more empty seats"); } }
public void sort_buss() { passengers compare = newPassengersGroup[0]; passengers temp = new passengers(0, "", 0); // int j = 1; for (int j = 0; j <= newPassengersGroup.Length - 2; j++) { for (int i = 0; i <= newPassengersGroup.Length - 2; i++) { if (newPassengersGroup[i] != null && newPassengersGroup[i + 1] != null) { if ((newPassengersGroup[i].age > newPassengersGroup[i + 1].age)) { temp = newPassengersGroup[i + 1]; newPassengersGroup[i + 1] = newPassengersGroup[i]; newPassengersGroup[i] = temp; } //System.Console.WriteLine("passengers sorted: {0}", newPassengersGroup[i].age); } else if (newPassengersGroup[i] == null && newPassengersGroup[i + 1] == null) { System.Console.WriteLine("not enough passenger to sort the ages"); break; } } } print_buss(); // for (int i = 0; i < newPassengersGroup.Length && j < newPassengersGroup.Length; i++, j++) // { // if (newPassengersGroup[i] != null && newPassengersGroup[j] != null) // { // if ((newPassengersGroup[i].age > newPassengersGroup[j].age)) // { // temp = newPassengersGroup[i]; // newPassengersGroup[i] = newPassengersGroup[j]; // newPassengersGroup[j] = temp; // j--; // } // System.Console.WriteLine("passengers sorted: {0}", newPassengersGroup[i].age); // } // } // System.Console.WriteLine("not enough passenger to sort the ages"); }