//Pilate therefore said to them, "Take him yourselves, and judge him according to your law." Therefore the Jews said to him, "It is not lawful for us to put anyone to death," (John 18:31) package com.javarush.task.task19.task1927; /* Контекстная реклама */ import java.io.*; public class Solution { public static TestString testString = new TestString(); public static void main(String[] args) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream stream = new PrintStream(baos); PrintStream systemOut = System.out; System.setOut(stream); testString.printSomething(); System.setOut(systemOut); BufferedReader reader = new BufferedReader(new StringReader(baos.toString())); String string; int count = 0; while ((string = reader.readLine()) != null) { System.out.println(string); if (++count % 2 == 0) { System.out.println("JavaRush - курсы Java онлайн"); } } } public static class TestString { public void printSomething() { System.out.println("first"); System.out.println("second"); System.out.println("third"); System.out.println("fourth"); System.out.println("fifth"); } } } /* Контекстная реклама В методе main подмени объект System.out написанной тобой реадер-оберткой. Твоя реадер-обертка должна выводить на консоль контекстную рекламу после каждого второго println-а. Вызови готовый метод printSomething(), воспользуйся testString. Верни переменной System.out первоначальный поток. Рекламный текст: «JavaRush - курсы Java онлайн» Пример вывода: first second JavaRush - курсы Java онлайн third fourth JavaRush - курсы Java онлайн fifth Требования: 1. Класс Solution должен содержать класс TestString. 2. Класс Solution должен содержать публичное статическое поле testString типа TestString, которое сразу проинициализировано. 3. Класс TestString должен содержать публичный void метод printSomething(). 4. Метод printSomething() класса TestString должен выводить на экран строки: "first","second","third","fourth","fifth". 5. Метод main(String[] args) класса Solution должен создавать поток PrintStream (используй PrintStream c параметром конструктора ByteArrayOutputStream). 6. Метод main(String[] args) класса Solution должен подменять и восстанавливать поток вывода в консоль объекта System.out. 7. Метод main(String[] args) класса Solution должен вызывать метод printSomething(),объекта testString. 8. Метод main(String[] args) класса Solution должен модифицировать строки(вставлять контекстную рекламу) выведенные методом printSomething() согласно заданию, и выводить её в консоль. package com.javarush.task.task19.task1927; * Контекстная реклама * public class Solution { public static TestString testString = new TestString(); public static void main(String[] args) { } public static class TestString { public void printSomething() { System.out.println("first"); System.out.println("second"); System.out.println("third"); System.out.println("fourth"); System.out.println("fifth"); } } } */