AirportManagement Part2Correction
AirportManagement Part2Correction
Staff
FirstName LastName EmailAddress BirthDate EmploymentDat Salary
e
captain captain [email protected] 01/01/1965 01/01/1999 99999
hostess1 hostess1 [email protected] 01/01/1995 01/01/2020 999
m
hostess2 hostess2 [email protected] 01/01/1996 01/01/2020 999
m
Travellers
FirstName LastName EmailAddress BirthDate HealthInform Nationality
ation
Traveller1 Traveller1 Traveller1. 01/01/1980 No troubles American
[email protected]
Traveller2 Traveller2 Traveller2. 01/01/1981 Some troubles French
[email protected]
1/3
Traveller3 Traveller3 Traveller3. 01/01/1982 No troubles Tunisian
[email protected]
Traveller4 Traveller4 Traveller4. 01/01/1983 Some troubles American
[email protected]
Traveller5 Traveller5 Traveller5. 01/01/1984 Some troubles Spanish
[email protected]
Flights
FlightDate Destination EffectiveArrival Plane EstimatedDuration Passengers
01/01/2022 Paris 01/01/2022 Airbus 110 All created travellers
15:10:10 17:10:10
01/02/2022 Paris 01/02/2022 Boing 105
21:10:10 23:10:10
01/03/2022 Paris 01/03/2022 Boing 100
5:10:10 6:40:10
01/04/2022 Madrid 01/04/2022 Boing 130
6:10:10 8:10:10
01/05/2022 Madrid 01/05/2022 Boing 105
17:10:10 18:50:10
01/06/2022 Lisbonne 01/06/2022 Airbus 200
20:10:10 22:30:10
Dans la même classe, créer la liste statique List<Flight> listFlights et l’initialiser avec tous
les vols crées précédemment.
2/3
new DateTime(1981, 01, 01), HealthInformation = "Some troubles", Nationality =
"French" };
public static Traveller traveller3 = new Traveller { FirstName = "traveller3",
LastName = "traveller3", EmailAddress = "[email protected]", BirthDate =
new DateTime(1982, 01, 01), HealthInformation = "no troubles", Nationality =
"Tunisian" };
public static Traveller traveller4 = new Traveller { FirstName = "traveller4",
LastName = "traveller4", EmailAddress = "[email protected]", BirthDate =
new DateTime(1983, 01, 01), HealthInformation = "Some troubles", Nationality =
"American" };
public static Traveller traveller5 = new Traveller { FirstName = "traveller5",
LastName = "traveller5", EmailAddress = "[email protected]", BirthDate =
new DateTime(1984, 01, 01), HealthInformation = "Some troubles", Nationality =
"Spanish" };
// Flights
// Affect all passengers to flight1
public static Flight flight1 = new Flight { FlightDate = new DateTime(2022, 01, 01,15,10,10), Destination =
"Paris", EffectiveArrival = new DateTime(2022, 01, 01,17,10,10),EstimatedDuration=110 , Passengers= new
List<Passenger> { captain, hostess1, hostess2, traveller1, traveller2, traveller3, traveller4, traveller5 }
,Plane= Airbusplane };
public static Flight flight2 = new Flight { FlightDate = new DateTime(2022, 02, 01,21,10,10), Destination =
"Paris", EffectiveArrival = new DateTime(2022, 02, 01, 23, 10, 10), EstimatedDuration =105 , Plane = BoingPlane };
public static Flight flight3 = new Flight { FlightDate = new DateTime(2022, 03, 01, 5, 10, 10), Destination =
"Paris", EffectiveArrival = new DateTime(2022, 03, 01, 6, 40, 10), EstimatedDuration = 100, Plane = BoingPlane };
public static Flight flight4 = new Flight { FlightDate = new DateTime(2022, 04, 01, 6, 10, 10), Destination =
"Madrid", EffectiveArrival = new DateTime(2022, 04, 01, 8, 10, 10), EstimatedDuration =130 , Plane = BoingPlane
};
public static Flight flight5 = new Flight { FlightDate = new DateTime(2022, 05, 01, 17, 10, 10), Destination =
"Madrid", EffectiveArrival = new DateTime(2022, 05, 01, 18, 50, 10), EstimatedDuration =105 , Plane = BoingPlane
};
public static Flight flight6 = new Flight { FlightDate = new DateTime(2022, 06, 01, 20, 10, 10), Destination =
"Lisbonne", EffectiveArrival = new DateTime(2022, 06, 01, 22, 30, 10), EstimatedDuration =200 , Plane =
Airbusplane };
//test list
public static List<Flight> listFlights = new List<Flight> { flight1, flight2,
flight3, flight4, flight5, flight6 };
}
5. Dans le projet console, créer une instance de la classe FlightMethods puis affecter
listFlights à la propriété Flights de cette classe service.
FlightMethods fm = new FlightMethods();
fm.Flights = TestData.listFlights;
Tester toutes les méthodes qui suivent en se basant sur ces données de test.
3/3
for (int j = 0; j < Flights.Count; j++)
if (Flights[j].Destination.Equals(destination))
ls.Add(Flights[j].FlightDate);
return ls;
}}
Console.WriteLine(f);
}
break;
case "EffectiveArrival":
foreach (Flight f in Flights)
{
if (f.EffectiveArrival == DateTime.Parse(filterValue))
Console.WriteLine(f);
}
break; }
}
Implémenter les méthodes suivantes et les tester à chaque fois dans le projet Console
4/3
where f.Destination.Equals(destination)
select f.FlightDate;
return req.ToList();
10. Afficher les dates et les destinations des vols d’un avion passé en paramètre
i. ShowFlightDetails(Plane plane)
public void ShowFlightDetails(Plane plane)
{
var req = from f in Flights
where f.Plane == plane
select new{f.FlightDate, f.Destination};
foreach(var v in req)
Console.WriteLine("Flight Date; "+v.FlightDate+" Flight destination: "+v.Destination);
}
ii.
11. Retourner le nombre de vols programmés pour une semaine (7jours) à partir d’une date
donnée
i. ProgrammedFlightNumber(DateTime startDate)
public int ProgrammedFlightNumber(DateTime startDate)
{
var req = from f in Flights
where DateTime.Compare(f.FlightDate,startDate)>0 && (f.FlightDate - startDate).TotalDays < 7
select f;
return req.Count();
12. Retourner la moyenne de durées estimées des vols d’une destination donnée
i. DurationAverage(string destination)
public double DurationAverage(string destination)
{
return (from f in Flights
where f.Destination.Equals(destination)
select f.EstimatedDuration).Average();
}
13. Retourner les Vols ordonnés par EstimatedDuration du plus long au plus court
i. OrderedDurationFlights()
public IEnumerable<Flight> OrderedDurationFlights()
{
var req = from f in Flights
orderby f.EstimatedDuration descending
select f;
return req;
}
14. Retourner les nationalités des 3 passagers, de type traveller, les plus âgés d’un vol
i. SeniorTravellers(Flight flight)
5/3
public IEnumerable<String> SeniorTravellers(Flight f)
{
15. Retourner les vols groupés par destination et les afficher sous ce format :
Destination Paris
Décollage : 03/05/2022 12 : 10 :00
Décollage : 05/05/2022 23 : 00 :00
Décollage : 10/05/2022 21 : 15 :00
Destination Madrid
Décollage : 01/05/2022 10 : 10 :00
Décollage : 02/05/2022 13 : 10 :00
i. DestinationGroupedFlights()
public IEnumerable<IGrouping<string, Flight>> DestinationGroupedFlights()
{
var req = from f in Flights
group f by f.Destination;
foreach (var g in req)
{ Console.WriteLine("Destination: " + g.Key);
foreach (var f in g)
Console.WriteLine("Décollage: " +f.FlightDate);
}
return req;
}
ii.
IV Expressions Lambda / Les méthodes LINQ prédéfinies
Tester
6/3
18. Affecter aux délégués le même traitement des méthodes ShowFlightDetails et
DurationAverage, mais à travers des méthodes anonymes (expressions Lambda).
// DurationAverageDel = DurationAverage;
DurationAverageDel = dest =>
{
return (from f in Flights
where f.Destination.Equals(dest)
select f.EstimatedDuration).Average();
};
// FlightDetailsDel = ShowFlightDetails;
FlightDetailsDel = p =>
{
var req = from f in Flights
where f.Plane == p
select new { f.FlightDate, f.Destination };
foreach (var v in req)
Console.WriteLine("Flight Date; " + v.FlightDate + " Flight destination: " + v.Destination);
};
Retester.
19. Reformuler toutes les méthodes de la section II en se basant sur les méthodes de requêtes
prédéfinies de la bibliothèque System.LINQ.
V Les méthodes d’extension
Dans le dossier Services, créer la classe PassengerExtension qui étend la classe Passenger et
qui contient la méthode d’extension UpperFullName() qui met en majuscule la première lettre
du nom et du prénom d’un passager.
public static class PassengerExtension
{
public static void UpperFullName(this Passenger p)
{
p.FirstName = p.FirstName[0].ToString().ToUpper() + p.FirstName.Substring(1);
p.LastName = p.LastName[0].ToString().ToUpper() + p.LastName.Substring(1);
}
}
7/3