0% found this document useful (0 votes)
2 views11 pages

TP Corecction

corecction de tp

Uploaded by

zakariaeechrigui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
2 views11 pages

TP Corecction

corecction de tp

Uploaded by

zakariaeechrigui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 11
On se propose de développer une application Java de gestion de livres, sachant qwun livre est caracténisé par son ID, son ttre et son auteur 1, Créer une interface IMetier définissant les méthodes suivantes : e Ajouter un livre. Chercher un livre par son 1D. © Afficher tous les livres. Supprimer un livre. 2. Créer la classe ImpIMetier implémentant IMétier. 3. Créer une classe de Test. | package smi.collections; public interface IMetier { a void ajouter (MY 1); void supprimer(int id); void afficherLivres(); Livre cherLivreParID(int id); 9} I 10 es ae =x% kaso Seated et Apc Cop Ft ne SHH ne Seat eap Os 0O-R-a- ease ® + 11 public int gettd() { eee ihe 1 return id; Ste 13 } Beenie 14 public String getTitre() { Fmommm 15 return titre; Himeactne 16 } 1p taroome 17 public String getAuteur() { | coro 18 return auteur; 19) = 20-@override poem 21 public String toString() { tet 2 // 1000 Auto-generated method stub a 3 return “Id="+id+":Titre="+titre+! ‘Auteur="*auteur;| 4} 25 private int id; 26 private String titre, auteur; 27} 28 - Erotic 1B Cesuten © concie Xf tem =*% S090 ~0 + Some 7 Apne Po p24 Taye ne BK HFT a yy yea 3 public class Livre { public Livre(int id, String titre, String auteur) { 4 s super(); 6 this.id = id; 7 this.titre = titre; 8 this.auteur = auteur; 9 } 1e 11 public int getId() { 12 return id; Jee 13} 14 public String getTitre() { 1s return titre; 16 } 17 public String getAuteur() { 18 return auteur; aay ‘ax ac BE - $ rethems = smasec iG Oecmater Oconee xX §? See Appin] Pega Fae pB 74 epee ne nce 26 TSF pe TE fret ae 11 public int getId() { 12 return id; 13} 14 public string getTitre() { 1s return titre; 16 } public String getauteur() { return auteur; @Override public String toString() { // 1000 Auto-generated method stub return “Id="+ide":Titres"+titres" :Auteur="+auteur;| 5 private int id; S private String titre,auteur; ' f Prcalems = images 1B Decnater © Corse Xf te ox e+e © stemmested> Tet (TD ana Appel] C\Progam Fes iw hI" ei premm ene QE now 256 TELS = 152 pe 1526) 7 Snes meet Bee package smi.collections; * 9 import java.util. ArrayList; import java.util-Hashset; = 5 import java.util. LinkedList; » © import java.util.List; import java.util.set; Be public class ImplMetier implements INetier { Spe 10 public Implmetier() { Sao 1 Livresenew HashSet<>(); ae } = eoverride public void ajouter(Livre 1) { 7/ TODO Auto-generated method stub Livres. add(1); package smi.collections; * 3 import java.util.arraylist; 4 import java.util.Hashset; © 5 import java.util. Linkedtist; s & 6 import java.util.List; 7 ? import java.util.set; 9 public class ImplMetier implements Imetier { 10 public ImplMetier() { un Livressnew Hashsete>(); 12 } override public void ajouter(Livre 1) { // 1000 Auto-generated method stub livres.add(1); + override public void supprimer(int id) { . |: em public void supprimer(int id) { // YO00 Auto-generated method stub for(int is@;iclivres.size();it+) { if(Livres.contains(this.cherLivreParI0(id))==true) livres.remove((this.cherLivrePar: , d @override public void afficherLivres() { // To00 Auto-generated method stub System.out.printIn( livres); } @override public Livre cherLivreParID(int id), { // T000 auto-generated method stub for(Livre 1:livres) { if(L.getId()=*id) return } wees EEDGOINIY = Der errr Ac void supprimer(int id) { // YO00 Auto-generated method stub for(int isO;iclivres.size();it+) { if (Livres. contains (this. cherLivreParID(id)): rue) Livres renove(ithis..cherLivreParID(id)) ; d ride 9 ic void affichertivres() { #30 // TODO Auto-generated method stub min SYStem.out.printIn(livres); rride lic Livre cherLivreParro(int id) { 11 T000 Auto-generated method stub for(Livre l:livres) { if(L.getId()=*id) return 1; recone: CEST SS ee ee public class Test { public static void main(string[] args) { // 1000 Auto-generated method stud ImplMetier o=new InplNetier(); o.ajouter(new Livre(2,"Algebre","ahnadi"))5 o.ajouter(new Livre(2, "Analyse", "Idrissi"))5 o.ajouter(new Livre(3,"C","Ahmadi")); o.afficherLivres(); Scanner senew Scanner(Systen. in); System.out.printIn("entrer 1'id du livre int n=s.nextInt(); o.suppriner(n); o.afficherLivres(); system.out.printIn("Entrer 1'id du livre 2 int m=s.nextInt(); Livre Iso. cherLivreParID(m); System.out.printIn(1); & supprimer:"); teow ESCO eer eee # 4G import java.util. Iterator; import java.util. List; 7 public class Main { public static void main(string[] args) { // 000 Auto-generated method stub snew ArrayList<>(); ne ha List h2 al.add(“Lundi"); 3 al.add( Mardi"); 4 al.add(“Nercredi"); Ss al.add(“Jeudi"); Iterator itersal.iterator(); while(iter.hasNext()) { String seiter.next();] aes

You might also like