-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutor.java
More file actions
34 lines (28 loc) · 842 Bytes
/
Autor.java
File metadata and controls
34 lines (28 loc) · 842 Bytes
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
import java.text.SimpleDateFormat;
import java.util.Date;
public class Autor {
private Integer id;
private String nome;
private Date dataNascimento;
private static int contadorId = 0;
public Autor(String nome, Date dataNascimento) {
this.id = gerarIdUnico();
this.nome = nome;
this.dataNascimento = dataNascimento;
}
private static synchronized int gerarIdUnico() {
return ++contadorId;
}
public Integer getId() {
return id;
}
public String getNome() {
return nome;
}
@Override
public String toString() {
SimpleDateFormat formatoData = new SimpleDateFormat("dd/MM/yyyy");
String dataFormatada = formatoData.format(dataNascimento);
return String.format("Autor: %d - %s, %s", id, nome, dataFormatada);
}
}