TP

Plateforme de livraison de repas — Java POO

Lancement

javac Main.java
java Main
Le programme compile les fichiers nécessaires test par test. Si une question échoue, les autres tests continuent.

Organisation du projet

src/
  ex1_modele/
  ex2_commandes/
  ex3_livraison/
evaluation/
Main.java

Les fichiers à compléter sont dans src. Le dossier evaluation contient le correcteur automatique et ne doit pas être modifié.

Barème

ExercicePointsNotions évaluées
Exercice 1 — Modèle métier7classes, héritage, protected, override, ArrayList, Iterator, Factory, equals/hashCode
Exercice 2 — Commandes7HashMap, exceptions, Singleton
Exercice 3 — Livraison6interfaces, Strategy, Observer, Adapter, Streams

Exercice 1 — Modèle métier, collections et Factory

1.1 Classe abstraite Plat 1 point

Fichiers : src/ex1_modele/Plat.java, src/ex1_modele/PlatChaud.java.

À compléter : constructeur, getters et description().

Plat p = new PlatChaud("PIZZA", "Pizza reine", 12.5);

Résultat attendu : getCode() retourne PIZZA, getNom() retourne Pizza reine, getPrix() retourne 12.5, et description() contient le code et le nom.

1.2 Héritage, protected et override 1.5 points

Fichiers : PlatChaud.java, Dessert.java, Boisson.java.

1.3 equals() et hashCode() 2 points

Fichier : Plat.java.

Règle métier : deux plats sont égaux s’ils ont le même code.

Plat p1 = new PlatChaud("PIZZA", "Pizza reine", 12);
Plat p2 = new PlatChaud("PIZZA", "Pizza fromage", 10);

HashSet<Plat> set = new HashSet<>();
set.add(p1);
set.add(p2);

Résultat attendu : set.size() == 1.

1.4 Factory 1.5 points

Fichier : PlatFactory.java.

public static Plat creer(String type, String code, String nom, double prix)

1.5 Restaurant, ArrayList et Iterator 1 point

Fichier : Restaurant.java.

Compléter ajouterPlat, getMenu, nombrePlats et supprimerPlatsTropChers.

La suppression doit utiliser un Iterator.

Exercice 2 — Commandes, HashMap, exceptions, Singleton

2.1 Inventaire avec HashMap 2 points

Fichier : Commande.java.

Une commande associe un code de plat à une quantité.

ajouter("PIZZA");
ajouter("PIZZA");
ajouter("COCA");

Résultat attendu : PIZZA = 2, COCA = 1, un code inconnu donne 0.

2.2 Total de commande 1.5 points

Méthode : total(Map<String, Double> prixCatalogue).

Test : 2 PIZZA à 12 € + 1 COCA à 3 €.

Résultat attendu : 27.0.

2.3 Exception commande vide 1 point

Fichiers : CommandeVideException.java, Commande.java.

Si la commande est vide, valider() doit lever CommandeVideException.

2.4 Exception stock insuffisant 1.5 points

Fichiers : StockInsuffisantException.java, Commande.java.

Si la quantité commandée est supérieure au stock disponible, verifierStock doit lever StockInsuffisantException.

2.5 Singleton JournalCommandes 1 point

Fichier : JournalCommandes.java.

getInstance() doit toujours retourner la même instance. Un message ajouté via une référence doit être visible via l’autre.

Exercice 3 — Livraison, Strategy, Observer, Adapter, Streams

3.1 Strategy 1 point

Fichiers : StrategieLivraison.java, LivraisonRapide.java, LivraisonEconomique.java.

3.2 Livraison avec stratégie interchangeable 1 point

Fichier : Livraison.java.

La livraison doit utiliser la stratégie courante et permettre de la changer avec setStrategie.

3.3 Observer 1.5 points

Fichiers : ObservateurCommande.java, CommandeObservable.java, SuiviClient.java.

CommandeObservable doit notifier ses observateurs quand son état change. SuiviClient doit mémoriser le dernier message reçu.

3.4 Adapter 1 point

Fichiers : Livreur.java, AncienLivreur.java, LivreurAdapter.java.

LivreurAdapter doit contenir un AncienLivreur privé et adapter sa méthode codeAncien() vers getIdentifiant().

3.5 Streams 1.5 points

Fichiers : CommandeInfo.java, AnalyseCommandes.java.