-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
37 lines (31 loc) · 1.29 KB
/
Solution.java
File metadata and controls
37 lines (31 loc) · 1.29 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
import java.time.LocalDate;
import java.util.Scanner;
public class Solution {
private static final int DAY_PENALTY = 15;
public static final int MONTH_PENALTY = 500;
private static LocalDate parseDate(Scanner sc) {
int day = sc.nextInt();
int month = sc.nextInt();
int year = sc.nextInt();
return LocalDate.of(year, month, day);
}
private static int getFine(LocalDate returnDate, LocalDate dueDate) {
if (returnDate.isBefore(dueDate)) return 0;
if (returnDate.getYear() == dueDate.getYear() && returnDate.getMonth() == dueDate.getMonth())
return DAY_PENALTY * (returnDate.getDayOfMonth() - dueDate.getDayOfMonth());
if (returnDate.getYear() == dueDate.getYear())
return MONTH_PENALTY * (returnDate.getMonth().getValue() - dueDate.getMonth().getValue());
return 10000;
}
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
// Parse actual return date
LocalDate returnDate = parseDate(sc);
// Parse actual return date
LocalDate dueDate = parseDate(sc);
System.out.println(getFine(returnDate, dueDate));
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}