-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlateletDonation.java
76 lines (72 loc) · 2.58 KB
/
PlateletDonation.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
package BloodDonationApp;
import java.util.Date;
public class PlateletDonation extends Donation{
//instanstan variable
private final String Ideal_BloodTYPEs[]={"A positive", "A positive", "B negative", "O positive", "AB positive", "AB negative",};
private final int WaitingPeriod = 7;
private final int AboveTo = 24;
/***************************************************
* *
* this Infrastructure of class Platelet Donation *
* to inherts from perents class Donation *
* *
* *************************************************/
public PlateletDonation(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 PlateletDonation)
count++;
}
if(count>AboveTo )
return false;
else
return true;
}
@Override
public String toString() {
return "Platelet, "+"Date: " + super.toString();
}
}