Hi
I have no clou what´s wrong here. The last three conditions are not met and the only hint from the site is that the requirements are not met. I assume we have to check that all entered times should be processed properly, but I miss more feedback to figure out what´s wrong.
Whould be very nice if someone could give me a hint. :)
Best regards
Eike
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);
// Clock clock = new Clock("London", 01, 58, 57);
Thread.sleep(4000);
isStopped = true;
Thread.sleep(1000);
}
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
this.seconds++;
Thread.sleep(1000);
if (this.seconds == 59 && this.hours == 23 && this.minutes == 59) {
System.out.println(
String.format("In %s, the time is now %02d:%02d:%02d!", cityName, hours, minutes, seconds));
this.hours = 0;
this.minutes = 0;
this.seconds = 0;
Thread.sleep(1000);
System.out.println(String.format("It's currently midnight in %s!", cityName));
} else if (this.seconds == 59 && this.hours < 23 && this.minutes == 59) {
System.out.println(
String.format("In %s, the time is now %02d:%02d:%02d!", cityName, hours, minutes, seconds));
this.hours += 1;
this.minutes = 0;
this.seconds = 0;
Thread.sleep(1000);
System.out.println(
String.format("In %s, the time is now %02d:%02d:%02d!", cityName, hours, minutes, seconds));
} else if (this.seconds == 59 && this.hours < 23 && this.minutes < 59) {
System.out.println(
String.format("In %s, the time is now %02d:%02d:%02d!", cityName, hours, minutes, seconds));
this.hours += 0;
this.minutes += 1;
this.seconds = 0;
Thread.sleep(1000);
System.out.println(
String.format("In %s, the time is now %02d:%02d:%02d!", cityName, hours, minutes, seconds));
}
else {
System.out.println(
String.format("In %s, the time is now %02d:%02d:%02d!", cityName, hours, minutes, seconds));
}
}
}
}