Skip to content

Commit e883c20

Browse files
authored
Create Alaram-clock
fixes #363
1 parent 6d20963 commit e883c20

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Alaram-clock

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

0 commit comments

Comments
 (0)