Programme Client/Commande problème de contraintes
Bonjour,
Je suis sur un programme simple avec des clients qui effectuent une ou plusieurs commandes.
Je souhaiterai qu'une commande ne puisse correspondre qu'à un seul client.
Classe Commande :
Code:
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
| public class Commande {
private int num;
private String date;
List<LigneCommande> lignes = new ArrayList<LigneCommande>();
public Commande(int num, String date) {
super();
this.num = num;
this.date = date;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public void addLigne(LigneCommande l) {
lignes.add(l);
} |
Classe Client :
Code:
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
| public class Client {
private String code;
private String nom;
List<Commande> commandes = new ArrayList<Commande>();
public Client(String code, String nom) {
super();
this.code = code;
this.nom = nom;
}
public String toString(){
return code+" "+nom;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public void addCommande(Commande c){
commandes.add(c);
} |
Mais dans mon MAIN je peux toujours associer un commande à plusieurs clients, voila ce qui me dérange. Je souhaiterai qu'on me l'interdise.
Classe Main :
Code:
1 2 3 4 5 6 7 8 9 10
| Produit p1 = new Produit(001,"tv",1500);
LigneCommande l1 = new LigneCommande(p1,1);
Client cli1 = new Client("1515","durant");
Client cli2 = new Client("1512","dupont");
Commande c1 = new Commande(001,"24 nov");
c1.addLigne(l1);
cli1.addCommande(c1);
cli2.addCommande(c1); |
Merci