File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .Timer ;
2+ import java .util .TimerTask ;
3+ import java .text .SimpleDateFormat ;
4+ import java .util .Date ;
5+
6+ public class AlarmClock {
7+
8+ public static void main (String [] args ) {
9+ // Set the alarm time (24-hour format)
10+ String alarmTime = "15:30" ; // Change this to your desired alarm time
11+
12+ // Create a timer
13+ Timer timer = new Timer ();
14+
15+ // Define a task to be executed when the alarm time is reached
16+ TimerTask task = new TimerTask () {
17+ public void run () {
18+ SimpleDateFormat sdf = new SimpleDateFormat ("HH:mm" );
19+ String currentTime = sdf .format (new Date ());
20+ if (currentTime .equals (alarmTime )) {
21+ System .out .println ("Alarm! It's time to wake up!" );
22+ // You can replace the message with any action you want
23+ }
24+ }
25+ };
You can’t perform that action at this time.
0 commit comments