-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData.java
More file actions
172 lines (153 loc) · 3.05 KB
/
Data.java
File metadata and controls
172 lines (153 loc) · 3.05 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* Francesco Garbo
* Classe Data
* 24/02/2017
* Progetto ASl
**/
/**
@author Garbo Francesco
@version 1.0
*/
public class Data{
private int giorno;
private int mese;
private int anno;
/**
* metodo per settare la data
* @param giorno giorno
* @param mese mese
* @param anno anno
* */
public boolean setData(int giorno, int mese, int anno){
boolean bisesto=false;
boolean giusto=false;
// controllo anno bisestile
if(anno%4 == 0){
if(anno%100 == 0) {
if(anno%400 == 0) {
// bisestile
bisesto = true;
}else {
// non bisestile
bisesto = false;
}
}
}else {
// non bisestile
bisesto = false;
}
//controllo g/m/a
if(anno<=0){
// L'anno non puo' essere inferiore a 0
giusto=false;
}
switch(mese){
case 1: if (giorno <= 31 && giorno>0){
giusto=true;
}else{
//Gennaio puo' avere un massimo di 31 giorni
giusto=false;
}break;
case 2:if (bisesto == true){
if (giorno <= 29 && giorno>0){
giusto=true;
}else {
giusto=false;
}
} else{
if (giorno <= 28){
giusto=true;
}else{
giusto=false;
}
}
break;
case 3: if (giorno <= 31 && giorno>0){
giusto=true;
}else{
giusto=false;
}break;
case 4: if (giorno <= 30 && giorno>0){
giusto=true;
}else{
giusto=false;
}break;
case 5: if (giorno <= 31 && giorno>0){
giusto=true;
}else{
giusto=false;
}
case 6: if (giorno <= 30 && giorno>0){
giusto=true;
}else{
giusto=false;
}break;
case 7: if (giorno <= 31 && giorno>0){
giusto=true;
}else{
giusto=false;
}break;
case 8: if (giorno <= 31 && giorno>0){
giusto=true;
}else{
giusto=false;
}break;
case 9: if (giorno <= 30 && giorno>0){
giusto=true;
}else{
giusto=false;
}break;
case 10: if (giorno <= 31 && giorno>0){
giusto=true;
}else{
giusto=false;
}break;
case 11: if (giorno <= 30 && giorno>0){
giusto=true;
}else{
giusto=false;
}break;
case 12: if (giorno <= 31 && giorno>0){
giusto=true;
}else{
giusto=false;
}break;
default : giusto=false;
}
if (giusto){
this.giorno=giorno;
this.mese=mese;
this.anno=anno;
}
return giusto;
}
/**
* Metodo get giorno
* @return Ritorna il giorno
* */
public int getGiorno(){
return giorno;
}
/**
* Metodo get mese
* @return Ritorna il mese
* */
public int getMese(){
return mese;
}
/**
* Metodo get anno
* @return Ritorna l'anno
* */
public int getAnno(){
return anno;
}
/**
* toString
* @return stringa con tutti i dati
* */
public String toString(){
String data;
data = giorno+"-"+mese+"-"+anno;
return data;
}
}