Помогите, пожалуйста, с пунктом 4 (обновлено)
package com.javarush.task.task16.task1632;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/*
Клубок
*/
public class Solution {
public static List<Thread> threads = new ArrayList<>(5);
static {
Thread yarn1 = new Thread(new Yarn1(), "Yarn1");
threads.add(yarn1);
Thread yarn2 = new Thread(new Yarn2(), "Yarn2");
threads.add(yarn2);
Thread yarn3 = new Thread(new Yarn3(), "Yarn3");
threads.add(yarn3);
Thread yarn4 = new Thread(new Yarn4(), "Yarn4");
threads.add(yarn4);
Thread yarn5 = new Thread(new Yarn5(), "Yarn5");
threads.add(yarn5);
}
public static class Yarn1 implements Runnable {
private static boolean isInterrupted;
public void run() {
while (!isInterrupted) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public static class Yarn2 implements Runnable {
private static boolean isInterrupted;
public void run() {
while (!isInterrupted) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
System.out.println("InterruptedException");
}
}
}
}
public static class Yarn3 implements Runnable {
private static boolean isInterrupted;
public void run() {
while (!isInterrupted) {
try {
System.out.println("Ура");
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
}
}
public static class Yarn4 implements Runnable, Message {
public void run() {
while (true) {
try {
Thread.sleep(500);
showWarning();
} catch (InterruptedException e) {
}
}
}
@Override
public void showWarning() {
if (Thread.currentThread().isAlive()) {
Thread.currentThread().interrupt();
}
}
}
public static class Yarn5 implements Runnable {
public void run() {
int sum = 0;
Scanner scanner = new Scanner(System.in);
while (true) {
String enteredString = scanner.nextLine();
if (!enteredString.equals("N")) {
System.out.println(sum);
break;
} else {
int newEnteredNumber = Integer.parseInt(enteredString);
sum = sum + newEnteredNumber;
}
}
}
}
public static void main(String[] args) {
for (Thread thread : threads) {
thread.start();
}
}
}