Task 1:

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.

Task 2:

Extends the class Clock to a CalendarClock by implementing the following components:

  • including information about year, month and day
  • toString method will return a string represent the date and time in format "dd/MM/yyyy hh:mm:ss", for example, 02/06/2020 14:30:00 for 2:30 pm of the 2nd of June in year 2020.
  • Corresponding get and set methods are required.
  • Following methods are required:
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
  • You need to consider the influence of a leaf year. A year is defined as:
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.

Task 3:

Extends the class Clock to a TimezoneClock by implementing the following components:

  • use an integer to represent the time zone, for example, 10 to indicate UTC+10:00, which is Melbourne time, and -5 to indicate UTC-5:00, which is US Eastern time.
  • toString method will return a time with timezone information, for example, "14:20:00 UTC+10:00" representing 2:20 pm at UTC+10:00, which is equivalent to 12:20:00 UTC+8:00

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.

Task 4:

Create a desktop program with JFrame and JPanel to display date and time information in the window.

  • Consider a date dd/MM/yyyy dd is the first digit of your student ID MM is the second digit of your student ID yyyy is 2020
  • Consider the time 14:50:06 at time zone +Z:00, where Z is the last digit of your student ID
  • You need to show the following information in your panel: Current date and time at time zone +Z:00 The corresponding time only for time zone +10:00 The corresponding time only for time zone -5:00
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.