-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEmployes.java
More file actions
280 lines (218 loc) · 6.99 KB
/
Copy pathEmployes.java
File metadata and controls
280 lines (218 loc) · 6.99 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*******************************************
* Completez le programme a partir d'ici.
*******************************************/
import java.text.NumberFormat;
import java.util.*;
class Employe{
private final String nom;
private double revenuMensuel;
private int tauxOccupation;
private String type;
private double montantPrime = 0;
public String retourneType(){
return "";
}
public Employe(String nom, double revenuMensuel, int tauxOccupation) {
this.nom = nom;
this.revenuMensuel = revenuMensuel;
if (tauxOccupation <10){
this.tauxOccupation=10;
} else{
if (tauxOccupation >100){
this.tauxOccupation=100;
} else{
this.tauxOccupation = tauxOccupation;
}
}
System.out.println("Nous avons un nouvel employé : " + nom + "," + retourneType());
}
public Employe(String nom, double revenuMensuel) {
this(nom, revenuMensuel, 100);
}
public double getRevenuMensuel() {
return revenuMensuel;
}
public void setRevenuMensuel(int revenuMensuel) {
this.revenuMensuel = revenuMensuel;
}
public double getTauxOcupation() {
return tauxOccupation;
}
public void setTauxOcupation(int tauxOcupation) {
this.tauxOccupation = tauxOcupation;
}
public String getNom() {
return nom;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public double revenuAnnuel(){
return (12*revenuMensuel*tauxOccupation/100) + montantPrime;
}
@Override
public String toString() {
String txtPrime="";
if (montantPrime!=0){
txtPrime = ", Prime : " + montantPrime;
}
return nom + " :\n Taux d'occupation : " + tauxOccupation + "%. Salaire annuel : " + revenuAnnuel() + " francs" + txtPrime + ".\n";
}
public void demandePrime(){
double primeDemandee=0;
boolean success = true;
Number number;
int nbEssais = 0;
String saisie;
Scanner clavier = new Scanner(System.in);
NumberFormat format = NumberFormat.getInstance(Locale.FRANCE);
do{
try
{
System.out.println("Montant de la prime souhaitée par " + nom + " ?");
success = true;
nbEssais++;
saisie = clavier.next();
number = format.parse(saisie);
primeDemandee = number.doubleValue();
//primeDemandee = clavier.nextLine();
}
catch ( Exception ex )
{
success = false;
System.out.println("Vous devez introduire un nombre!" );
}
if (success && (primeDemandee > (revenuAnnuel()*2/100))){
System.out.println("Trop cher!" );
} else {
if (success){montantPrime = primeDemandee;}
}
}
while((!success || primeDemandee > (revenuAnnuel()*2/100)) && (nbEssais < 5));
//clavier.next();
//clavier.close();
}
}
class Manager extends Employe{
private int nbJoursVoyages;
private int nbNouveauClients;
public final static int FACTEUR_GAIN_CLIENT = 500;
public final static int FACTEUR_GAIN_VOYAGE = 100;
public String retourneType(){
return " c'est un manager.";
}
public int getNbJoursVoyages() {
return nbJoursVoyages;
}
public void setNbJoursVoyages(int nbJoursVoyages) {
this.nbJoursVoyages = nbJoursVoyages;
}
public int getNbNouveauClients() {
return nbNouveauClients;
}
public void setNbNouveauClients(int nbNouveauClients) {
this.nbNouveauClients = nbNouveauClients;
}
public Manager(String nom, double revenuMensuel, int nbJoursVoyages, int nbNouveauClients, int tauxOcupation) {
super(nom, revenuMensuel, tauxOcupation);
this.nbJoursVoyages = nbJoursVoyages;
this.nbNouveauClients = nbNouveauClients;
// TODO Auto-generated constructor stub
}
public Manager(String nom, double revenuMensuel, int nbJoursVoyages, int nbNouveauClients) {
this(nom, revenuMensuel,nbJoursVoyages, nbNouveauClients,100);
}
public double revenuAnnuel(){
return super.revenuAnnuel() + nbNouveauClients*FACTEUR_GAIN_CLIENT + nbJoursVoyages*FACTEUR_GAIN_VOYAGE;
}
public String toString() {
return super.toString() + " A voyagé " + nbJoursVoyages + " jours et apporté " + nbNouveauClients + " nouveaux clients.";
}
}
class Programmeur extends Employe{
private int nbProjetsAcheves;
public final static int FACTEUR_GAIN_PROJETS = 200;
public String retourneType(){
return " c'est un programmeur.";
}
public int getNbProjetsAcheves() {
return nbProjetsAcheves;
}
public void setNbProjetsAcheves(int nbProjetsAcheves) {
this.nbProjetsAcheves = nbProjetsAcheves;
}
public Programmeur(String nom, double revenuMensuel, int nbProjetsAcheves, int tauxOcupation) {
super(nom, revenuMensuel, tauxOcupation);
// TODO Auto-generated constructor stub
this.nbProjetsAcheves = nbProjetsAcheves;
}
public Programmeur(String nom, double revenuMensuel, int nbProjetsAcheves) {
this(nom, revenuMensuel, nbProjetsAcheves, 100);
}
public double revenuAnnuel(){
return super.revenuAnnuel() + nbProjetsAcheves*FACTEUR_GAIN_PROJETS;
}
public String toString() {
String proj;
if(nbProjetsAcheves>1){
proj = " projets";
} else {proj = " projet";}
return super.toString() + " A mené à bien " + nbProjetsAcheves + proj;
}
}
class Testeur extends Employe{
private int nbErreursCorrigees;
public final static int FACTEUR_GAIN_ERREURS = 10;
public String retourneType(){
return " c'est un testeur.";
}
public int getNbErreursCorrigees() {
return nbErreursCorrigees;
}
public void setNbErreursCorrigees(int nbErreursCorrigees) {
this.nbErreursCorrigees = nbErreursCorrigees;
}
public Testeur(String nom, double revenuMensuel, int nbErreursCorrigees, int tauxOcupation) {
super(nom, revenuMensuel, tauxOcupation);
this.nbErreursCorrigees = nbErreursCorrigees;
}
public Testeur(String nom, double revenuMensuel, int nbErreursCorrigees) {
this(nom, revenuMensuel, nbErreursCorrigees,100);
}
public double revenuAnnuel(){
return super.revenuAnnuel() + nbErreursCorrigees*FACTEUR_GAIN_ERREURS;
}
public String toString() {
return super.toString() + " A corrigé " + nbErreursCorrigees + " erreurs.";
}
}
/*"Montant de la prime souhaitée par "
/*******************************************
* Ne rien modifier apres cette ligne.
*******************************************/
class Employes {
public static void main(String[] args) {
List<Employe> staff = new ArrayList<Employe>();
// TEST PARTIE 1:
System.out.println("Test partie 1 : ");
staff.add(new Manager("Serge Legrand", 7456, 30, 4 ));
staff.add(new Programmeur("Paul Lepetit" , 6456, 3, 75 ));
staff.add(new Testeur("Pierre Lelong", 5456, 124, 50 ));
System.out.println("Affichage des employés : ");
for (Employe modele : staff) {
System.out.println(modele);
}
// FIN TEST PARTIE 1
// TEST PARTIE 2
System.out.println("Test partie 2 : ");
staff.get(0).demandePrime();
staff.get(0).demandePrime();
staff.get(0).demandePrime();
System.out.println("Affichage après demande de prime : ");
System.out.println(staff.get(0));
// FIN TEST PARTIE 2
}
}