-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDifferentDateImpl.java
More file actions
31 lines (25 loc) · 1.18 KB
/
Copy pathDifferentDateImpl.java
File metadata and controls
31 lines (25 loc) · 1.18 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
package com.yurii.salimov.lesson06.task01;
import java.util.Date;
public final class DifferentDateImpl implements DifferentDate {
private final Date firstDate;
private final Date secondDate;
public DifferentDateImpl(final Date firstDate, final Date secondDate) {
this.firstDate = firstDate;
this.secondDate = secondDate;
}
@Override
public void printDifferent() {
if (this.firstDate.equals(this.secondDate)) {
System.out.println("Dates are equivalent");
} else {
if ((this.firstDate.getDate() != (this.secondDate.getDate())) ||
(this.secondDate.getMonth() != (this.firstDate.getMonth())) ||
(this.secondDate.getYear() != (this.firstDate.getYear()))) {
System.out.print("The difference between your and system date is ");
System.out.print((this.secondDate.getYear() - this.firstDate.getYear()) + " year ");
System.out.print((this.secondDate.getMonth() - this.firstDate.getMonth()) + " month and ");
System.out.println((this.secondDate.getDate() - this.firstDate.getDate()) + " days.");
}
}
}
}