CS 1103 - Programming Assignment Unit 3
CS 1103 - Programming Assignment Unit 3
import java.text.SimpleDateFormat;
import java.util.Date;
class Clock {
// Method to continuously update and print the current time
public static void displayTime() {
// Create a thread for continuously updating the time
Thread updateTimeThread = new Thread(() -> {
while (true) {
try {
// Update the time
updateCurrentTime();
// Sleep for 1 second
Thread.sleep(1000);
} catch (InterruptedException e) {
System.err.println("Error in updateTimeThread: " + e.getMessage());
Thread.currentThread().interrupt();
}
}
});
Program Screenshot
Program Video
Clock-Application.mp4
Program Documentation
Overview
The Clock application is a simple Java program that continuously displays the current
time and date. It utilizes Java threads to update the time in the background and print it
to the console. Thread priorities are used to ensure better timekeeping precision.
Features
Clock Class
● displayTime(): Method to continuously update and print the current time.
● updateCurrentTime(): Method to update the current time and date.
● printCurrentTime(): Method to print the current time to the console.
● main(): The main method to start the application.
Thread Implementation
● Two separate threads are used: one for updating the time and one for printing it
to the console.
● Thread priorities are set to ensure timely console output.