package com.codegym.task.task16.task1613;
/*
Big Ben
*/
public class Solution {
public static volatile boolean isStopped = false;
public static void main(String[] args) throws InterruptedException {
Clock clock = new Clock("London", 23, 59, 57);
Thread.sleep(4000);
isStopped = true;
Thread.sleep(1000);
isStopped = false;
}
public static class Clock extends Thread {
private String cityName;
private int hours;
private int minutes;
private int seconds;
public Clock(String cityName, int hours, int minutes, int seconds) {
this.cityName = cityName;
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
start();
}
public void run() {
try {
while (!isStopped) {
printTime();
}
} catch (InterruptedException e) {
}
}
private void printTime() throws InterruptedException {
//write your code here
// increment seconds
seconds++;
// create conditionals for hours, minutes and seconds
if (seconds == 60)
{
minutes++;
seconds = 0;
if (minutes == 60)
{
hours++;
minutes = 0;
if (hours == 24)
{
hours = 0;
}
}
}
// else if (seconds == 1) {
// isStopped = true;
// }
if (hours == 0 && minutes == 0 && seconds == 0) {
System.out.println(String.format("It's currently midnight in %s!", cityName));
} else {
System.out.println(String.format("In %s, the time is now %02d:%02d:%02d!", cityName, hours, minutes, seconds));
}
}
}
}
Can't get the first task to pass?
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Thomas
17 June 2021, 05:32
0