-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass DataException3
87 lines (39 loc) · 1.69 KB
/
Class DataException3
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
if (ano < 0)
throw new DateException();
if(ano % 4 == 0) {
this.dcs = true;
}
else {
this.ano = ano;
this.finaldia[1] = 28;
this.dcs = false;
}
}
public void setM(int M) throws DateException{
if (M < 1 || M >12)
throw new DateException();
this.M = M;
}
public void setD(int D) throws DException, AnoException {
if (D >= 1 || D <= 31) {
if (D <= finaldia[M-1]) {
this.D = D;
}
else if (D == 29 && dcs == true && M == 2){
this.D = D;
System.out.println "Ano Bissexto![D= "+ this.D +" , M= "+ this.M +" , ano= "+ this.ano +"]";
}
else if (D == 29 && dcs == false && M == 2) {
System.out.println
throw new AnoException();
}
else {
System.out.println"[D= "+ this.D +" , M= "+ this.M +" , ano= "+ this.ano +"]";
throw new DException();
}
}
}
public static void main(String [] args)throws DateException, AnoException {
Date alimport java.lang.Exception;
public class AnoException extends Exception{
public AnoException() {