回答編集履歴
1
誤ったファイル名を変更
test
CHANGED
@@ -1,4 +1,512 @@
|
|
1
|
+
```Employee
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
public abstract class Employee {
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
private String name;
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
public Employee(String name) {
|
14
|
+
|
15
|
+
super();
|
16
|
+
|
17
|
+
this.name = name;
|
18
|
+
|
19
|
+
}
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
public String getName() {
|
24
|
+
|
25
|
+
return name;
|
26
|
+
|
27
|
+
}
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
public void setName(String name) {
|
32
|
+
|
33
|
+
this.name = name;
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
@Override
|
40
|
+
|
41
|
+
public String toString() {
|
42
|
+
|
43
|
+
return "Employee [name=" + name + "]";
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
@Override
|
50
|
+
|
51
|
+
public boolean equals(Object arg0) {
|
52
|
+
|
53
|
+
Employee other = (Employee) arg0;
|
54
|
+
|
55
|
+
return this.getName().equalsIgnoreCase(other.getName());
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
```
|
70
|
+
|
71
|
+
|
72
|
+
|
1
|
-
```
|
73
|
+
```Exective
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
public class Executive extends SalesCommisioned{
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
private double incrementPercentage;
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
public Executive(String name, double commissionRate, double monthSales, double incrementPercentage) {
|
86
|
+
|
87
|
+
super(name, commissionRate, monthSales);
|
88
|
+
|
89
|
+
this.incrementPercentage = incrementPercentage;
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
public double getIncrement() {
|
96
|
+
|
97
|
+
return incrementPercentage;
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
public void setIncrement(double incrementPercentage) {
|
104
|
+
|
105
|
+
this.incrementPercentage = incrementPercentage;
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
public double annualSalary() {
|
112
|
+
|
113
|
+
return super.earnings()*12;
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
public double earningsAnnual() {
|
120
|
+
|
121
|
+
return (1+incrementPercentage/100) * annualSalary();
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
@Override
|
128
|
+
|
129
|
+
public String toString() {
|
130
|
+
|
131
|
+
return "Executive [increment=" + incrementPercentage + "]";
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
@Override
|
138
|
+
|
139
|
+
public boolean equals(Object arg0) {
|
140
|
+
|
141
|
+
Employee other = (Employee) arg0;
|
142
|
+
|
143
|
+
return this.getName().equalsIgnoreCase(other.getName());
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
```
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
```SalesCommisioned
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
public class SalesCommisioned extends Employee{
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
private double commissionRate; // commission percentage
|
168
|
+
|
169
|
+
private double monthSales; // gross monthly sales
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
public SalesCommisioned(String name, double commissionRate, double monthSales) {
|
174
|
+
|
175
|
+
super(name);
|
176
|
+
|
177
|
+
this.commissionRate = commissionRate;
|
178
|
+
|
179
|
+
this.monthSales = monthSales;
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
public double getCommissionRate() {
|
186
|
+
|
187
|
+
return commissionRate;
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
public void setCommissionRate(double commissionRate) {
|
194
|
+
|
195
|
+
this.commissionRate = commissionRate;
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
public double getMonthSales() {
|
202
|
+
|
203
|
+
return monthSales;
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
public void setMonthSales(double monthSales) {
|
210
|
+
|
211
|
+
this.monthSales = monthSales;
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
public double earnings() {
|
218
|
+
|
219
|
+
return (1+getCommissionRate()/100) * getMonthSales();
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
@Override
|
226
|
+
|
227
|
+
public String toString() {
|
228
|
+
|
229
|
+
return "SalesCommisioned [commissionRate=" + commissionRate + ", monthSales=" + monthSales + "]";
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
@Override
|
236
|
+
|
237
|
+
public boolean equals(Object arg0) {
|
238
|
+
|
239
|
+
Employee other = (Employee) arg0;
|
240
|
+
|
241
|
+
return this.getName().equalsIgnoreCase(other.getName());
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
}
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
```
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
```HourlyPaid
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
public class HourlyPaid extends Employee{
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
public double wage;//wage per hour
|
266
|
+
|
267
|
+
public double hours;//total hours in a week
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
public HourlyPaid(String name, double wage, double hours) {
|
274
|
+
|
275
|
+
super(name);
|
276
|
+
|
277
|
+
this.wage = wage;
|
278
|
+
|
279
|
+
this.hours = hours;
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
public double getWage() {
|
288
|
+
|
289
|
+
return wage;
|
290
|
+
|
291
|
+
}
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
public void setWage(double wage) {
|
298
|
+
|
299
|
+
this.wage = wage;
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
public double getHours() {
|
308
|
+
|
309
|
+
return hours;
|
310
|
+
|
311
|
+
}
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
public void setHours(double hours) {
|
318
|
+
|
319
|
+
this.hours = hours;
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
public double earnings() {
|
328
|
+
|
329
|
+
if (getHours() <= 40) {//Not Overworked
|
330
|
+
|
331
|
+
return getHours()*getWage();
|
332
|
+
|
333
|
+
}
|
334
|
+
|
335
|
+
//If it is more than 40 hours per week in Japan, hourly paid must times "1.25"
|
336
|
+
|
337
|
+
else return getWage()*40 + getWage()*1.25*(getHours()-40);
|
338
|
+
|
339
|
+
}
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
@Override
|
346
|
+
|
347
|
+
public String toString() {
|
348
|
+
|
349
|
+
return "HourlyPaid [wage=" + wage + ", hours=" + hours + "]";
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
@Override
|
356
|
+
|
357
|
+
public boolean equals(Object arg0) {
|
358
|
+
|
359
|
+
Employee other = (Employee) arg0;
|
360
|
+
|
361
|
+
return this.getName().equalsIgnoreCase(other.getName());
|
362
|
+
|
363
|
+
}
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
}
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
```
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
```TestEmployee
|
378
|
+
|
379
|
+
import java.util.ArrayList;
|
380
|
+
|
381
|
+
import java.util.List;
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
public class TestEmployee {
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
public static void main(String[] args) {
|
390
|
+
|
391
|
+
// TODO Auto-generated method stub
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
List<Object> emps= new ArrayList<Object>();
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
int i = 0;
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
HourlyPaid hourlyPaid = new HourlyPaid( "Anne Bronte", 7.5, 45);
|
406
|
+
|
407
|
+
SalesCommisioned salesCommisioned = new SalesCommisioned("Emily Bronte", 30, 90);
|
408
|
+
|
409
|
+
Executive exective = new Executive("Charlotte Bronte", 12, 123, 30);
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
emps.add(i, hourlyPaid);
|
414
|
+
|
415
|
+
i++;
|
416
|
+
|
417
|
+
emps.add(i, salesCommisioned);
|
418
|
+
|
419
|
+
i++;
|
420
|
+
|
421
|
+
emps.add(i, exective);
|
422
|
+
|
423
|
+
i++;
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
for ( Object currentEmp : emps ) {
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
System.out.println( currentEmp );
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
if( currentEmp instanceof HourlyPaid ) {
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
HourlyPaid employee = ( HourlyPaid ) currentEmp;
|
440
|
+
|
441
|
+
System.out.println("HourlyPaid Employee : " + employee.getName());
|
442
|
+
|
443
|
+
System.out.println("Hourly Wage : " + employee.getWage());
|
444
|
+
|
445
|
+
System.out.println("Earned(A Month) : " + employee.earnings());
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
System.out.println();
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
}else if ( currentEmp instanceof SalesCommisioned ) {
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
SalesCommisioned employee = ( SalesCommisioned ) currentEmp;
|
460
|
+
|
461
|
+
System.out.println("SalesCommisioned Employee : " + employee.getName());
|
462
|
+
|
463
|
+
System.out.println("Commisioned Rate : " + employee.getCommissionRate() + "%");
|
464
|
+
|
465
|
+
System.out.println("MonthSales : " + employee.getMonthSales());
|
466
|
+
|
467
|
+
System.out.println("Earned(A Month) : " + employee.earnings());
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
System.out.println();
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
}
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
if ( currentEmp instanceof Executive ){
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
Executive employee = ( Executive ) currentEmp;
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
System.out.println("AnnualSalay is " + employee.annualSalary() + " with IncrementRate " + employee.getIncrement() + "%");
|
488
|
+
|
489
|
+
System.out.println("Earned(A year) : " + employee.earningsAnnual());
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
System.out.println();
|
494
|
+
|
495
|
+
}
|
496
|
+
|
497
|
+
}
|
498
|
+
|
499
|
+
}
|
500
|
+
|
501
|
+
}
|
502
|
+
|
503
|
+
|
504
|
+
|
505
|
+
```
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
```UnitTest
|
2
510
|
|
3
511
|
import org.junit.Assert;
|
4
512
|
|