-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerson.java
More file actions
140 lines (127 loc) · 2.62 KB
/
Copy pathPerson.java
File metadata and controls
140 lines (127 loc) · 2.62 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* Representing a Person object to store data entries with fields of name
* and birthday. Implementation of Comparable interface allows precedence of one
* person over another using alphabetic order of the name field.
* @author Jesse Clegg
* @version 1.0
*/
import java.util.*;
public class Person implements Comparable<Person> {
/*
* First and Last name delimited by space character
*/
private String Name;
/*
* Birthday in format 'YYYY-MM-DD'
*/
private String Birthday;
/**
* default no arg constructor
*/
Person() {
this.Name = null;
this.Birthday = null;
}
/**
* @param name the name to set
*/
Person(String name) {
this.Name = name;
this.Birthday = null;
}
/**
* @param name
* @param birthday
*/
public Person(String name, String birthday) {
this.Name = name;
if (birthday.length() == 10) {
this.Birthday = birthday;
} else {
this.Birthday = null;
}
}
/**
* @return name of this person for printing/accessing from a generic class
* without casting
*/
@Override
public String toString() {
return this.Name;
}
/**
*
* @return first 4 characters of birthday 'YYYY'
*/
public String getYear() {
if (this.Birthday == null || this.Birthday.length() != 10) {
return null;
} else {
StringBuilder year = new StringBuilder();
for (int i = 0; i < 4; i++) {
year.append(this.getBirthday().charAt(i));
}
return year.toString();
}
}
/**
*
* @return characters 5-6 of birthday 'MM'
*/
public String getMonth() {
if (this.Birthday == null || this.Birthday.length() != 10) {
return null;
} else {
StringBuilder month = new StringBuilder();
for (int i = 5; i < 7; i++) {
month.append(this.getBirthday().charAt(i));
}
return month.toString();
}
}
/**
* @return last 2 characters of birthday 'DD'
*/
public String getDay() {
if (this.Birthday == null || this.Birthday.length() != 10) {
return null;
} else {
StringBuilder day = new StringBuilder();
for (int i = 8; i < 10; i++) {
day.append(this.getBirthday().charAt(i));
}
return day.toString();
}
}
/**
* @return the name
*/
public String getName() {
return Name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
Name = name;
}
/**
* @return the birthday
*/
public String getBirthday() {
return Birthday;
}
/**
* @param birthday the birthday to set
*/
public void setBirthday(String birthday) {
Birthday = birthday;
}
/**
* @param other a person class to compare field of name with
*/
@Override
public int compareTo(Person other) {
return Name.compareTo(other.Name);
}
}