-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFail.java
More file actions
47 lines (45 loc) · 1.24 KB
/
Fail.java
File metadata and controls
47 lines (45 loc) · 1.24 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
import java.util.Scanner;
import java.util.HashMap;
public class Main {
public static void main(String[] args) {
}
}
class MyDate {
public int year;
public int month;
public int day;
HashMap<Integer, Integer> monthDay = new HashMap<Integer, Integer>();
monthDay.put(1, 31);
monthDay.put(3, 31);
monthDay.put(5, 31);
monthDay.put(7, 31);
monthDay.put(8, 31);
monthDay.put(10, 31);
monthDay.put(12, 31);
public MyDate(int year, int month, int day) throws Exception {
if (year < 1 || year > 9999) {
throw new IllegalArgumentException("year error");
}
if (month < 1 || month > 12) {
throw new IllegalArgumentException("month error");
}
if (day < 1 || day > 31) {
throw new IllegalArgumentException("day error");
}
this.year = year;
this.month = month;
this.day = day;
}
public static int sub (MyDate d1, MyDate d2) {
int daysFromMonth;
if (d1.month == 2) {
if (d1.year%4) {
daysFromMonth = 28
} else {
// TODO
}
}
= monthDay.getOrDefault(d1.month, 30);
d1.year * 365 + d1.month
}
}