Does anyone know anyway to pass the requirement relating to thread 4? I have tried the other solutions mentioned on other answers and haven't been able to pass.
package com.codegym.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 {
Class1 c1 = new Class1();
Class2 c2 = new Class2();
Class3 c3 = new Class3();
Class4 c4 = new Class4();
Class5 c5 = new Class5();
Thread thread1 = new Thread(c1);
Thread thread2 = new Thread(c2);
Thread thread3 = new Thread(c3);
Thread thread4 = new Thread(c4);
Thread thread5 = new Thread(c5);
threads.add(thread1);
threads.add(thread2);
threads.add(thread3);
threads.add(thread4);
threads.add(thread5);
}
public static void main(String[] args) {
for (Thread t: threads) {
t.start();
}
}
public static class Class1 extends Thread {
public void run() {
while(true) {
}
}
}
public static class Class2 extends Thread {
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("InterruptedException");
}
}
}
public static class Class3 extends Thread {
public void run() {
try {
while (true) {
System.out.println("Hurray");
Thread.sleep(500);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static class Class4 extends Thread implements Message {
boolean going = true;
public void showWarning() {
going = false;
}
@Override
public void run() {
while(going){
}
}
}
public static class Class5 extends Thread {
static boolean numberOrNot(String input) {
try {
Integer.parseInt(input);
} catch(NumberFormatException ex) {
return false;
}
return true;
}
public static void count() {
Scanner sc = new Scanner(System.in);
int total = 0;
while (true) {
String input = sc.next();
if (numberOrNot(input)) {
total += Integer.parseInt(input);
}
if (input.equals("N")) {
break;
}
}
System.out.println(total);
}
public void run() {
count();
}
}
}