bonsoir tous le monde
j'ai essayé de faire l'exercice suivant je veux savoir est ce que mon essai est correcte :
l'ennoncé :
Nom : exerice3.png
Affichages : 168
Taille : 60,4 Ko
class Client :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
package Pharmacie;
 
public class Client {
	String nom;
	String prenom;
	int num_carte;
 
	public Client(String nom, String prenom, int num_carte) {
		this.nom = nom;
		this.prenom = prenom;
		this.num_carte = num_carte;
	}
 
 
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Client other = (Client) obj;
		if (nom == null) {
			if (other.nom != null)
				return false;
		} else if (!nom.equals(other.nom))
			return false;
		if (num_carte != other.num_carte)
			return false;
		if (prenom == null) {
			if (other.prenom != null)
				return false;
		} else if (!prenom.equals(other.prenom))
			return false;
		return true;
	}
 
 
 
}
class Pharmacie
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
package Pharmacie;
 
public class Pharmacie {
 
 
	 String nom;
	 String adress ;
	 Client[] clients ;
	 Produit[] produit ;
 
	public Pharmacie(String nom, String adress, Client[] clients, Produit[] produit) {
		this.nom = nom;
		this.adress = adress;
		this.clients = clients;
		this.produit = produit;
	}
 
	private boolean clientExiste(Client c){
		for(int i=0;i<this.clients.length;i++){
		if(this.clients[i].equals(c)){
		return true ;	
		}
		}
		return false ;
	}
	private boolean produitExiste(Produit p){
		for(int i=0;i<this.clients.length;i++){
			if(this.produit[i].equals(p)){
			return true ;	
			}
			}
			return false ;
	}
    void acheter(Produit p ,Client c,int q) {
 
    	if(!this.clientExiste(c)){
    		System.out.println("Client n'existe pas");
    		return;
    	}
    	if(!this.produitExiste(p)){
    		System.out.println("Produit n'existe pas");
    		return;
    	}
 
    	if(p.getQuantite_stock()<q){
    		System.out.println("Quantite insuffisant ");
    	}
    	else{
    		p.setQuantite_stock(p.getQuantite_stock()-q);
    	   System.out.println("l'achat a bien effectuer \n le stock a etait mis a jour");
    	}
 
    } 
 
    void approvisionnement(Produit p,int q){
    	if(!this.produitExiste(p)){
    		System.out.println("Produit n'existe pas");
    		return;
    	}
    	p.setQuantite_stock(p.getQuantite_stock()+q);
    	System.out.println("le stock a etait mis a jour");
 
    }
 
 
}
class Parapharmacie
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
package Pharmacie;
 
public class Parapharmacie extends Pharmacie {
 
		String type;
 
		public Parapharmacie(String nom, String adress, Client[] clients, Produit[] produit, String type) {
			super(nom, adress, clients, produit);
			this.type = type;
		}
 
 
}
class Medicament
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
package Pharmacie;
 
public class Medicament extends Pharmacie {
 
		boolean generique;
		boolean ordonnance ;
		public Medicament(String nom, String adress, Client[] clients, Produit[] produit, boolean generique,
				boolean ordonnance) {
			super(nom, adress, clients, produit);
			this.generique = generique;
			this.ordonnance = ordonnance;
		}
 
 
}
class Produit
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
package Pharmacie;
 
 public class Produit {
 
		String reference;
		double prix;
		int quantite_stock;
 
		public Produit(String reference, double prix, int quantite_stock) {
 
			this.reference = reference;
			this.prix = prix;
			this.quantite_stock = quantite_stock;
		}
 
 
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Produit other = (Produit) obj;
			if (Double.doubleToLongBits(prix) != Double.doubleToLongBits(other.prix))
				return false;
			if (quantite_stock != other.quantite_stock)
				return false;
			if (reference == null) {
				if (other.reference != null)
					return false;
			} else if (!reference.equals(other.reference))
				return false;
			return true;
		}
 
 
		public void setQuantite_stock(int quantite_stock) {
			this.quantite_stock = quantite_stock;
		}
 
 
		public int getQuantite_stock() {
			return quantite_stock;
		}
 
 
}