JAVA
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
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class Program
{
private static class RegisteredPerson {
final String name;
LocalDate birthdate;
public RegisteredPerson(final String givenName) {
this.name = givenName;
}
public RegisteredPerson(final String givenName, final LocalDate givenBirthDate) {
this.name = givenName;
this.birthdate = givenBirthDate;
}
public RegisteredPerson(final String givenName, final String givenBirthDate) {
this.name = givenName;
try {
final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy");
final LocalDate parsedDate = LocalDate.parse(givenBirthDate, dtf);
this.birthdate = parsedDate;
} catch (final Exception ex) {
// add error handling
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run