forked from java-tester-x/JavaExercises4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestMyDate.java
More file actions
30 lines (24 loc) · 1.24 KB
/
TestMyDate.java
File metadata and controls
30 lines (24 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
package src;
public class TestMyDate {
public static void main(String[] args)
{
MyDate currentDate = new MyDate(2014, 7, 2);
System.out.println("Current date: " + currentDate);
MyDate d1 = new MyDate(2012, 2, 28);
System.out.println(d1); // Tuesday 28 Feb 2012
System.out.println(d1.nextDay()); // Wednesday 29 Feb 2012
System.out.println(d1.nextDay()); // Thursday 1 Mar 2012
System.out.println(d1.nextMonth()); // Sunday 1 Apr 2012
System.out.println(d1.nextYear()); // Monday 1 Apr 2013
MyDate d2 = new MyDate(2012, 1, 2);
System.out.println(d2); // Monday 2 Jan 2012
System.out.println(d2.previousDay()); // Sunday 1 Jan 2012
System.out.println(d2.previousDay()); // Saturday 31 Dec 2011
System.out.println(d2.previousMonth()); // Wednesday 30 Nov 2011
System.out.println(d2.previousYear()); // Tuesday 30 Nov 2010
MyDate d3 = new MyDate(2012, 2, 29);
System.out.println(d3.previousYear()); // Monday 28 Feb 2011
// MyDate d4 = new MyDate(2099, 11, 31); // Invalid year, month, or day!
// MyDate d5 = new MyDate(2011, 2, 29); // Invalid year, month, or day!
}
}