Вроде как выводит правильно, но все равно валидатор не принимает.
package com.javarush.task.task16.task1612;
/*
Stopwatch (Секундомер)
*/
public class Solution {
public static volatile boolean isStopped = false;
public static void main(String[] args) throws InterruptedException {
Runner ivanov = new Runner("Ivanov", 4);
Runner petrov = new Runner("Petrov", 2);
//на старт!
//внимание!
//марш!
ivanov.start();
petrov.start();
Thread.sleep(2000);
isStopped=true;
}
public static class Stopwatch extends Thread {
private Runner owner; //"Иванов", 4
private int stepNumber; //0
public Stopwatch(Runner runner) {
this.owner = runner;
}
public void run() {
try {
while (!isStopped) {
doStep();
}
} catch (InterruptedException e) {
}
}
private void doStep() throws InterruptedException {
Thread.sleep(1000/this.owner.getSpeed());
stepNumber++;
System.out.println(owner.getName() + " делает шаг №" + stepNumber + "!");
}
}
public static class Runner {
Stopwatch stopwatch; //
private String name; //="Иванов"
private int speed; //=4
public Runner(String name, int speed) {
this.name = name;
this.speed = speed;
this.stopwatch = new Stopwatch(this); //(new Runner("Иванов", 4))
}
public String getName() {
return name;
}
public int getSpeed() {
return speed;
}
public void start() {
stopwatch.start();
}
}
}