-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsommable.java
120 lines (90 loc) · 1.95 KB
/
Consommable.java
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
/**
* Classe abstraite definissant le concept de consommable
* Transmet les caracteristiques standards aux consommables specifiques
*/
public abstract class Consommable {
/**
* Attributs permettant de definir le consommable
* Compteur de consommables crees
*/
private String nom;
private double prix;
private int x, y;
private static int nbConsommables = 0;
/**
* Constructeur 01
*
* @param n : nom du consommable
* @param p : prix du consommable
*/
public Consommable(String n, double p) {
nom = n;
prix = p;
nbConsommables++;
}
/**
* Constructeur 02
*
* @param n : nom du consommable
* @param p : prix du consommable
* @param x : abscisse du consommable
* @param y : ordonnee du consommable
*/
public Consommable(String n, double p, int x, int y) {
this(n, p);
this.x = x;
this.y = y;
}
/**
* Redefinition de la methode standard toString()
*
* @return le nom et le prix du consommable
*/
@Override
public String toString() {
return nom + ", Prix : " + prix;
}
/**
* Redefinition de la methode standard equals()
*
* @return l'egalite structurelle entre deux consommables
*/
@Override
public boolean equals(Object obj) {
if ((this.getClass() == obj.getClass()) && (this != null)) {
Consommable c = (Consommable) obj;
return (nom == c.nom) && (prix == c.prix) && (x == c.x) && (y == c.y);
}
return false;
}
/**
* Accesseurs
*/
public String getNom() {
return nom;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public double getPrix() {
return prix;
}
public static int getNbConsommables() {
return nbConsommables;
}
/**
* Mutateur
*/
public void setXY(int xx, int yy) {
x = xx; y = yy;
}
/**
* Methode abstraite clone()
*
* @return un consommable identique
*/
public abstract Consommable clone();
}