-
Notifications
You must be signed in to change notification settings - Fork 0
/
PowerRedDonation.java
77 lines (71 loc) · 2.53 KB
/
PowerRedDonation.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
package BloodDonationApp;
import java.util.Date;
/*************************************************
* *
* this Infrastructure of class power Donation *
* to inherts from perents class Donation *
* *
* **********************************************/
public class PowerRedDonation extends Donation{
private final String Ideal_BloodTYPEs[]={"O positive", "O negative", "A negative", "B negative"};
private final int WaitingPeriod = 112;
private final int AboveTo = 3;
public PowerRedDonation(Date donation_date) {
super(donation_date);
}
//cheack if the stutes == WaitingDateTST,testNumberOfDonation,testBloodType
public boolean Availability(Donor donor){
boolean status=true;
if (!testBloodType(donor)){
status=false;
}
if (!WaitingDateTST(donor)){
status=false;
}
if (!testNumberOfDonation(donor)){
status=false;
}
return status;
}
//cheack if the WaitingDateTST == BLDDonations_TYPES
public boolean WaitingDateTST(Donor donor){
int index=donor.getBLDDonations_TYPES().size();
if(index>0){
Donation don=donor.getBLDDonations_TYPES().get(donor.getBLDDonations_TYPES().size()-1);
Date old_donation_date=don.getDate();
long diff = super.getDate().getTime() - old_donation_date.getTime();
diff=diff / (1000 * 60 * 60 * 24);
if(diff>WaitingPeriod){
return true;
}else{
return false;
}
}else{
return true;
}
}
//cheack if the testBloodType == Ideal Blood Types
public boolean testBloodType(Donor donor){
for(int i=0;i<Ideal_BloodTYPEs.length;i++){
if(donor.getBloodTYPE().equals(Ideal_BloodTYPEs[i]))
return true;
}
return false;
}
//count Number Of Donation
public boolean testNumberOfDonation(Donor donor){
int count=0;
for(Donation don:donor.getBLDDonations_TYPES()){
if(don instanceof PowerRedDonation)
count++;
}
if(count>AboveTo )
return false;
else
return true;
}
@Override
public String toString() {
return "Power Red, "+"Date: " + super.toString();
}
}