-
Notifications
You must be signed in to change notification settings - Fork 0
/
Studente.java
79 lines (67 loc) · 1.79 KB
/
Studente.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
package prg.es5;
import java.util.ArrayList;
import prg.es4.Date;
public class Studente{
private String nome;
private String cognome;
private Date data;
private long matricola;
private static ArrayList<Long> insiemeMatricole = new ArrayList<>(); //memorizza le matricole già impiegate
//COSTRUTTORI:
public Studente(String nome, String cognome, Date data, long matricola){
this.setName(nome);
this.setSurname(cognome);
this.setDate(data);
this.setMatricola(matricola);
}
//METODI:
public Studente setName(String nome){
this.nome = nome;
return this;
}
public Studente setSurname(String cognome){
this.cognome = cognome;
return this;
}
public Studente setDate(Date data){
this.data = data;
return this;
}
public Studente setMatricola(long matricola){ //formato: 0000000
if(matricola > 99999 && matricola < 10000000){
for(Long tmp : insiemeMatricole){ //controllo matricola univoca
if(tmp.longValue() == matricola){
System.out.println("Impossibile impostare matricola! Esiste gia' uno studente con tale matricola.");
return this;
}
}
this.matricola = matricola;
Long l = Long.valueOf(matricola);
insiemeMatricole.add(l);
}
return this;
}
public String getName(){
return this.nome;
}
public String getSurname(){
return this.cognome;
}
public Date getDate(){
return this.data;
}
public String stringDate(){
return this.data.toString2();
}
public Studente printDate(){
System.out.println(this.stringDate());
return this;
}
public long getMatricola(){
return matricola;
}
public Studente print(){
System.out.printf("%-10s\t%-10s\t%s\t%07d\n", this.getName(), this.getSurname(), this.stringDate(), this.getMatricola());
return this;
}
}