-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFournisseur.java
More file actions
121 lines (99 loc) · 3.21 KB
/
Copy pathFournisseur.java
File metadata and controls
121 lines (99 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
/** classe pour créer differents 4 fournisseurs: articles de ski, accessoires, boissons, nourritures */
public class Fournisseur {
private String nomFourni;
private ArrayList<Tuple<Article,Integer>> artfourni=new ArrayList <Tuple<Article,Integer>>();;
/** getter pour donner le nom du fourni
* @return le nom du fournisseur
*/
public String getNomFourni() {
return this.nomFourni;
}
/** constructeur Fournisseur
* @param m le magasin
*/
public Fournisseur (Magasin m) {
System.out.println("Nom du fournisseur ? ");
Scanner objet2=new Scanner (System.in);
String g=objet2.nextLine();
nomFourni=g;
System.out.println("Combien d'articles produisez vous ?");
Scanner objet = new Scanner (System.in);
int c=objet.nextInt();
Scanner yu =new Scanner(System.in);
int i=0;
while(i<c) {
System.out.println("Nom du produit: ");
String nom=yu.nextLine();
Article b=new Article(nom);
System.out.println("Combien en avez vous ?");
int d=objet.nextInt();
Tuple <Article,Integer>t3=new Tuple<Article, Integer>(b,d);
artfourni.add(t3);
i+=1;
}
}
/** constructeur fournisseur
* @param nom du fournisseur
* @param article qu'il fournit
* @param stock du fournisseur
*/
public Fournisseur(String nom, ArrayList<Article> article,int stock) {
this.nomFourni=nom;
Iterator <Article> it=article.iterator();
while(it.hasNext()) {
Article a=it.next();
Tuple<Article,Integer> t=new Tuple <Article,Integer> (a,stock);
artfourni.add(t);
}
}
/** methode pour afficher le nom du fournisseur ainsi que les articles qu'il vend et la quantité dont il dispose
*/
public void afficherProdFour() {
System.out.println("Nom du fournisseur: "+nomFourni);
Iterator<Tuple<Article,Integer>> it=artfourni.iterator();
while(it.hasNext()) {
Tuple<Article,Integer> t=it.next();
Article a=(Article) t.getT1();
Integer b=(Integer) t.getT2();
a.afficherArticle();
System.out.println("Disponibilité: "+b);
}
}
/** methode pour diminuer le stock d'un article chez le fournisseur
* @param a article dont on veut diminuer le stock
* @param x la quantite à enlever du stock
*/
public void diminuerDispo(Article a,int x) {
Iterator<Tuple<Article,Integer>> it=artfourni.iterator();
while(it.hasNext()) {
Tuple<Article,Integer> t=it.next();
if(t.getT1().getNom().equalsIgnoreCase(a.getNom())&& t.getT1().getCategorie().equalsIgnoreCase(a.getCategorie())) {
t.setT2(t.getT2()-x);
}
}
}
/** getter pour donner l'article et sa quantité
* @return la liste des articles ainsi que leur stock
*/
public ArrayList<Tuple<Article,Integer>> getArtfourni() {
return artfourni;
}
public void setArtfourni(ArrayList<Tuple<Article,Integer>> artfourni) {
this.artfourni = artfourni;
}
public static void main(String[] args) {
ArrayList <Article> a1=new ArrayList<Article>();
Article a=new Article("Ski",200,400,"P");
Article b=new Article ("Ski",100,200,"C");
Article c=new Article ("Ski",60,120,"E");
a1.add(a);
a1.add(b);
a1.add(c);
Fournisseur f=new Fournisseur("defe",a1,100);
f.diminuerDispo(a, 20);
f.afficherProdFour();
}
}