Task 1:
Convert following UML diagram to java code.
<<Interface>>
Ticker
-void Tick()
<<implements>>
<<Implements>>
-int day
-int month
-int year
Date
Date(int day, int month, int year)
+int getDate()
+int getMonth()
+int getYear()
+void setDate(int date)
+void setMonth(int month)
+void setYear(int year)
+String toString()
+void Tick()
-int seconds
-int minutes
-int hours
Time
+Time(int seconds, int minutes, int hours)
+int getSeconds()
+int getMinutes()
+int getHours()
+void setSeconds(int seconds)
+void setMinutes(int minutes)
+void setHours(int hours)
+String toString()
+void Tick()
Test Class:
Tick method in Time class
Increment in seconds and if second is equal to 60 rest it 0 and incremnt in minutes. If
minutes is equal to 60 rest minutes to 0 and increment in hours. If hours is equal to 24
rest it to 0.
Tick method in Date class
Increment in days, if day is equal to 30 rest it 1 and incremnt in month. If month is equal
to 12 rest month to 1 and increment in year.
Check expected output and create object of date and time class accordingly and call
toString() for both.
Now set data and time and and call toString().
Now create polymorphic reference of Ticker interface with name dateTime and call tick
method for date and time and then call toString().
Date(date=16, month=4, year=2019)
Time(seconds=1, minutes=2, hours=3)
Date(date=25, month=11, year=2019)
Time(seconds=55, minutes=55, hours=23)
Date(date=1, month=1, year=2020)
Time(seconds=0, minutes=0, hours=0)
BUILD SUCCESSFUL (total time: 0 seconds)