Consider implementing a class Clock, which contains the following attribute:
our (an integer from 0 to 23)
minute (an integer from 0 to 59)
second (an integer from 0 to 59)
and the following methods:
void setHour(int h);
//set hour according to h, where h can be any value
void setMinute(int m); //set minute according to m, where m can be any value
void setSecond(int s);
//set second according to s, where s can be any value
int getHour();
//return the current value of hour
int getMinute();
//return the current value of minute
int getSecond();
//return the current value of second
String toString();
//return a String in format of “hh:mm:ss”, for example, “15:45:37”
void addSeconds(int s); //add s seconds to the current time, and adjust minute and hour accordingly,
//where s can be a negative value
void addMinutes(int m); //add m minutes to the current time, and adjust hour accordingly,
//where m can be a negative value
void addHours(int h); //add h hours to the current time.
You are also required to put default constructor and other reasonable constructors to initial the time.
Draw a UML diagram for the class Clock.
Complete the class Clock and write a driven class to run it.
Design a few test cases to test the methods indicated.
Extends the class Clock to a CalendarClock by implementing the following components:
void addDays(int d) //add d days to the current date, and adjust month and year
//accordingly, where d can only be a positive value
void addMonths(int m) //add m months to the current date, and adjust year
//accordingly, where m can only be a positive value
void addYears(int y) //add y years to the current date
if year % 100 ==0 and year%400 == 0
year is a leaf year
else if year % 4 == 0
year is a leaf year
else
year is not a leaf year
A leaf year means that there are 29 days for February while there are only 28 days in a normal year.
You are also required to put default constructor and other reasonable constructors to initial the date and time.
Draw a UML diagram for the class CalendarClock with the relatationship to class Clock.
Complete the class CalendarClock and write a driven class to run it.
Design a few test cases to test the methods indicated.
Extends the class Clock to a TimezoneClock by implementing the following components:
You are also required to put default constructor and other reasonable constructors to initial the date and time.
Draw a UML diagram for the class TimezoneClock with the relatationship to class Clock.
Complete the class TimezoneClock and write a driven class to run it.
Design a few test cases to test the methods indicated.
Create a desktop program with JFrame and JPanel to display date and time information in the window.