-
Notifications
You must be signed in to change notification settings - Fork 9
/
DateDriver.java
56 lines (55 loc) · 1.97 KB
/
DateDriver.java
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
//*******************************************************
// DateDriver.java
// A main class for check the Date class
// Author: liron mizrahi
//*******************************************************
import java.util.Scanner;
public class DateDriver
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
// print to user
System.out.println("This program demonstrates the " + " usage of Date class");
System.out.println("Please enter the day, month, year");
// take user input
int day = scanner.nextInt();
int month = scanner.nextInt();
int year = scanner.nextInt();
// making 2 Date object
Date d1 = new Date(day, month, year);
Date d2 = new Date(d1.getDay(), d1.getMonth(), d1.getYear());
System.out.println("d1 = " + d1.toString());
System.out.println("d2 = " + d2.toString());
// test the methods in the class
if (d1.equals(d2))
{
System.out.println("Same Date");
}
else
{
System.out.println("Different Dates");
}
d1.setMonth(6);
System.out.println("new month in d1: " + d1.getMonth());
System.out.println("d1 = " + d1.toString());
d2.setYear(2022);
System.out.println("Updated year in d2: " + d2.getYear());
System.out.println("Updated d2 = " + d2.getDay() + "/" + d2.getMonth() + "/" + d2.getYear());
if (d1.equals(d2))
{
System.out.println("Same Date");
} else if (date2.before(date1))
{
System.out.println("the date before: " + date2);
System.out.println("the date after: " + date1);
}
else
{
System.out.println("the date before: " + date1);
System.out.println("the date after: " + date2);
}
// close the scanner object
scanner.close();
} // end of method main
} // end of class DateDriver