-
Notifications
You must be signed in to change notification settings - Fork 0
/
Volunteer.java
97 lines (75 loc) · 2.72 KB
/
Volunteer.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
import java.util.*;
import java.text.*;
public class Volunteer {
private String firstName;
private String lastName;
private char middleInitial;
private String dob; //MMDDYYYY
private int age;
private boolean phone;
private boolean canvasing;
private int currentYear;
private int currentMonth;
private int currentDay;
public Volunteer(String fn, String ln, char mi, String birthday, boolean ph, boolean canvas){
Date date = new Date();
String modifiedDate= new SimpleDateFormat("yyyy-MM-dd").format(date);
currentYear = Integer.parseInt(modifiedDate.substring(0,3));
currentMonth = Integer.parseInt(modifiedDate.substring(5,6));
currentDay = Integer.parseInt(modifiedDate.substring(8,9));
firstName = fn;
lastName = ln;
middleInitial = mi;
dob = birthday;
age = this.dobToAge();
phone = ph;
canvasing = canvas;
}
public int dobToAge(){
int month = Integer.parseInt(dob.substring(0,1));
int day = Integer.parseInt(dob.substring(2,3));
int year = Integer.parseInt(dob.substring(4,7));
int age = currentYear-year;
if(month>currentMonth){
return age-1;
}
else if(month == currentMonth){
if(day>=currentDay){
return age-1;
}
else{
return age;
}
}
else{
return age;
}
}
public int compareTo(Volunteer v){ //By last, then first, then MI, then DOB
if(0 != (this.lastName.compareTo(v.lastName))){
return this.lastName.compareTo(v.lastName);
}
else if(0 != (this.firstName.compareTo(v.firstName))){
return this.firstName.compareTo(v.firstName);
}
else if(this.middleInitial != v.middleInitial){
Character initial1 = this.middleInitial;
Character initial2 = v.middleInitial;
return initial1.compareTo(initial2);
}
else if(this.dob != v.dob){
return this.dob.compareTo(v.dob);
}
else{ //identical ppl
return 0;
}
}
public String toString() {
String name = "Name: "+firstName+" "+middleInitial+" "+lastName;
String ageOfVoter = "Date of Birth: "+dob;
String canvasStr = "Canvasing?: "+canvasing;
String phonebankStr = "Phonebanking?: "+phone;
String vol = name+" | "+ageOfVoter+" | "+canvasStr+" | "+phonebankStr;
return vol;
}
}