Question: Problem 1: 1- Implement a class Clock whose getHours() and getMinutes() methods return the current time of Saudi Arabia. Hint: Call java.time.Instant.now().toString() or, if you
Problem 1:
1- Implement a class Clock whose getHours() and getMinutes() methods return the current time of Saudi Arabia. Hint: Call java.time.Instant.now().toString() or, if you are not using Java 8, new java.util.Date().toString() and extract the time from that string.
2- Also provide a getTime() method that returns a string with the hours and minutes by calling the getHours() and getMinutes() methods.
3- Provide a subclass WorldClock whose constructor accepts a time offset. For example, a new WorldClock(1) should show the time in Dubai, one time zone ahead of Riyadh.
4- Which methods did you override? [You should not override getTime()]
5- Add an alarm feature to the Clock class. When setAlarm(hours, minutes) is called, the clock stores the alarm. When you call getTime(), and the alarm time has been reached or exceeded, return the time followed by the string "Alarm" and clear the alarm.
6- What do you need to do to make the setAlarm() method work for WorldClock objects?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
