public class VolCompletException extends Exception {
public VolCompletException(String message) {
super(message);
}
}
public class SiegeOccupeException extends Exception {
public SiegeOccupeException(String message) {
super(message);
}
}
public enum ClasseVol {
ECONOMIQUE("Economique"),
AFFAIRES("Affaires"),
PREMIERE("Première");
private String libelle;
ClasseVol(String libelle) {
[Link] = libelle;
}
public String getLibelle() {
return libelle;
}
}
import [Link];
public class Passager {
private String nom;
private String prenom;
private String numeroPasseport;
private LocalDate dateNaissance;
public Passager(String nom, String prenom, String
numeroPasseport, LocalDate dateNaissance) {
[Link] = nom;
[Link] = prenom;
[Link] = numeroPasseport;
[Link] = dateNaissance;
}
public int getAge() {
return [Link]().getYear() -
[Link]();
}
@Override
public String toString() {
return prenom + " " + nom + " (Passeport: " +
numeroPasseport + ")";
}
}
import [Link];
import [Link];
import [Link];
public class Vol {
private String numero;
private String destination;
private LocalDate date;
private int placesTotales;
private int placesReservees;
private Set<String> siegesOccupes;
private double prixBase;
public Vol(String numero, String destination,
LocalDate date, int placesTotales, double prixBase) {
[Link] = numero;
[Link] = destination;
[Link] = date;
[Link] = placesTotales;
[Link] = 0;
[Link] = new HashSet<>();
[Link] = prixBase;
}
public boolean estComplet() {
return placesReservees >= placesTotales;
}
public int getPlacesDisponibles() {
return placesTotales - placesReservees;
}
public double getPrixSelonClasse(String classe) {
switch ([Link]()) {
case "premiere": return prixBase * 3;
case "affaires": return prixBase * 2;
default: return prixBase;
}
}
public String reserverSiege(String siege) throws
SiegeOccupeException {
if ([Link](siege)) {
throw new SiegeOccupeException("Siège " +
siege + " déjà occupé");
}
[Link](siege);
return siege;
}
public void incrementerReservations() {
placesReservees++;
}
public void libererSiege(String siege) {
[Link](siege);
placesReservees--;
}
public String getNumero() { return numero; }
public String getDestination() { return destination; }
public LocalDate getDate() { return date; }
@Override
public String toString() {
return "Vol " + numero + " -> " + destination +
" (" + date + ") - " +
getPlacesDisponibles() + "/" +
placesTotales + " places disponibles";
}
}
import [Link];
public class Reservation {
private static int compteur = 1;
private int id;
private Vol vol;
private Passager passager;
private String siege;
private ClasseVol classe;
private LocalDate dateReservation;
private boolean confirmee;
public Reservation(Vol vol, Passager passager,
String siege, ClasseVol classe)
throws VolCompletException,
SiegeOccupeException {
if ([Link]()) {
throw new VolCompletException("Vol " +
[Link]() + " complet");
}
[Link] = compteur++;
[Link] = vol;
[Link] = passager;
[Link] = classe;
[Link] = [Link]();
[Link] = true;
[Link] = [Link](siege);
[Link]();
}
public double getPrix() {
return
[Link]([Link]().toLowerCase());
}
public void annuler() {
if (confirmee) {
confirmee = false;
[Link](siege);
[Link]("Réservation #" + id + "
annulée");
}
}
public void afficherDetails() {
[Link]("ID: " + id);
[Link]("Passager: " + passager);
[Link]("Vol: " + vol);
[Link]("Siège: " + siege);
[Link]("Classe: " + [Link]());
[Link]("Prix: " + getPrix() + " Euro");
[Link]("Date réservation: " +
dateReservation);
[Link]("Statut: " + (confirmee ?
"Confirmée" : "Annulée"));
[Link]("----------------------------------");
}
public int getId() { return id; }
public boolean estConfirmee() { return confirmee; }
public Vol getVol() { return vol; }
}
import [Link];
import [Link];
public class GestionnaireVols {
private List<Vol> vols = new ArrayList<>();
private List<Reservation> reservations = new
ArrayList<>();
public void ajouterVol(Vol vol) {
[Link](vol);
[Link]("Vol ajouté: " + vol);
}
public Reservation reserverVol(Vol vol,
Passager passager,
String siege,
ClasseVol classe) {
try {
Reservation r = new Reservation(vol, passager,
siege, classe);
[Link](r);
[Link]("Réservation créée: #" +
[Link]());
return r;
} catch (Exception e) {
[Link]("Erreur: " + [Link]());
return null;
}
}
public void annulerReservation(int id) {
for (Reservation r : reservations) {
if ([Link]() == id && [Link]()) {
[Link]();
return;
}
}
[Link]("Réservation non trouvée !");
}
}
import [Link];
public class TestGestionnaireVols {
public static void main(String[] args) {
GestionnaireVols gestionnaire = new
GestionnaireVols();
LocalDate demain = [Link]().plusDays(1);
LocalDate apresDemain =
[Link]().plusDays(2);
Vol vol1 = new Vol("AF123", "Paris", demain, 150,
300.0);
Vol vol2 = new Vol("BA456", "Londres", demain,
100, 250.0);
Vol vol3 = new Vol("LH789", "Berlin", apresDemain,
120, 280.0);
Vol vol4 = new Vol("AF124", "Paris", apresDemain,
200, 320.0);
[Link](vol1);
[Link](vol2);
[Link](vol3);
[Link](vol4);
Passager p1 = new Passager("Dupont", "Jean",
"AB123456",
[Link](1980, 5, 15));
Passager p2 = new Passager("Martin", "Sophie",
"CD789012",
[Link](1992, 8, 22));
Passager p3 = new Passager("Durand", "Pierre",
"EF345678",
[Link](1975, 3, 10));
[Link]("\n--- RESERVATIONS ---");
Reservation r1 = [Link](vol1, p1,
"12A", [Link]);
Reservation r2 = [Link](vol1, p2,
"12B", [Link]);
Reservation r3 = [Link](vol2, p3,
"1A", [Link]);
if (r1 != null) [Link]();
if (r2 != null) [Link]();
if (r3 != null) [Link]();
[Link]("\n--- ANNULATION ---");
if (r1 != null) {
[Link]([Link]());
}
[Link]("\n--- TEST SIEGE OCCUPE
---");
[Link](vol1, p3, "12B",
[Link]);
[Link]("\n--- FIN DU PROGRAMME
---");
}
}