-
Notifications
You must be signed in to change notification settings - Fork 0
/
Voter.java
68 lines (53 loc) · 2.09 KB
/
Voter.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
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class Voter {
private String firstName;
private String lastName;
private char middleInitial;
private int age;
private String location;
private String phoneNumber;
private String dateLastContacted; //YYYYMMDD
private String currentYear;
private String currentMonth;
private String currentDay;
public Voter(String name, int a, String loc, String phone, String lastCtc){
String[] items = name.split("\\s+");
ArrayList<String> nameList = new ArrayList<String>();
for(String n : items){
nameList.add(n);
}
if(nameList.size() == 2){ //no middleInitial
firstName = nameList.get(0);
lastName = nameList.get(1);
}
if(nameList.size() == 3){
firstName = nameList.get(0);
String miString = nameList.get(1);
middleInitial = miString.charAt(0);
lastName = nameList.get(2);
}
age = a;
location = loc;
phoneNumber = phone;
dateLastContacted = lastCtc;
}
public void dateLastContactedChanged() {
Date date = new Date();
String modifiedDate= new SimpleDateFormat("yyyy-MM-dd").format(date);
currentYear = modifiedDate.substring(0,3);
currentMonth = modifiedDate.substring(5,6);
currentDay = modifiedDate.substring(8,9);
dateLastContacted = currentYear+currentMonth+currentDay;
}
public String toString() {
String name = "Name: "+firstName+" "+middleInitial+""+lastName;
String ageOfVoter = "Age: "+age;
String locationOfVoter = "Location: "+location;
String phoneNumberOfVoter = "Phone: "+phoneNumber;
String dateLastCtcOfVoter = "Date Last Contacted: "+dateLastContacted;
String voter = name+" | "+ageOfVoter+" | "+locationOfVoter+" | "+phoneNumberOfVoter+" | "+dateLastCtcOfVoter;
return voter;
}
}