import java.text.
SimpleDateFormat;
import java.util.Date;
class Clock {
private final SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss dd-MM-
yyyy");
public void displayTime() {
String currentTime = formatter.format(new Date());
System.out.println("Current Time: " + currentTime);
}
}
class TimeUpdater extends Thread {
private final Clock clock;
public TimeUpdater(Clock clock) {
this.clock = clock;
}
@Override
public void run() {
while (true) {
try {
Thread.sleep(1000); // Simulate background logic
} catch (InterruptedException e) {
System.out.println("Updater Interrupted: " + e.getMessage());
}
}
}
}
class ClockDisplay extends Thread {
private final Clock clock;
public ClockDisplay(Clock clock) {
this.clock = clock;
}
@Override
public void run() {
while (true) {
clock.displayTime();
try {
Thread.sleep(1000); // Update every second
} catch (InterruptedException e) {
System.out.println("Display Interrupted: " + e.getMessage());
}
}
}
}
public class SimpleClockApp {
public static void main(String[] args) {
Clock clock = new Clock();
TimeUpdater updater = new TimeUpdater(clock);
ClockDisplay display = new ClockDisplay(clock);
updater.setPriority(Thread.MIN_PRIORITY);
display.setPriority(Thread.MAX_PRIORITY);
updater.start();
display.start();
}
}