Well, I give a more detailed answer.
First, the Worker class:
public class Worker { private Paragraph paragraph; //Конструктор public Worker(Paragraph p) { this.paragraph = p; } /* Далее методы по работе с текстом или что-то там еще надо сделать... */ }
As we remember, the paragraph creates a class Reader
. Next, you wonder what will be in the Paragraph
class. It should take one paragraph from the source file. The logic of implementation to come up with is a technical matter (i.e., yours). Those. in essence, it should take, for example, a string type, break it into sentences, as well as the class sentence (Sentence) should take a string type and break the accepted sentence into words and punctuation, and send them to its subclass - the word . Those. The logic is that each class must do its own . These are the basics of OOP . Here is the Paragraph class:
public class Paragraph { //Объявляем лист предложений private List<Sentence> sentenses; //Объявляем конструктор public Paragraph(String text) { sentenses = new ArrayList<Sentence>(); List<String> tSentenses = new ArrayList<String>(); /* Тут надо разбить пришедший текст на предложения, после чего получится лист строк, которые и будут предложениями. */ //Идем дальше: //Тут мы заполняем наш список предложений в классе for (String s : tSentenses) sentenses.add(new Sentence(s)); } /*Ну и, т.к. мы будем использовать в качестве основного источника получения всяких там данных из текста, то реализовать тут можно геттеры и сеттеры отдельных частей параграфа. А т.к. все предложения заносятся последовательно, то и порядок, конечно же, сохранится. */ public String getParagraphText() { //Будет совмещать назат весь параграф. Например так: String res = ""; // Извлекаем содержимое предложений из нашего класса. for (Sentence sent : sentenses) { res += sent.getSentenseText(); } return res; } }
By absolute analogy, make Sentence
class sentence . It is already clear that it must contain a constructor, which accepts a string type, and must contain at least a method that returns a sentence stored in it.
And note that there is a class in a class, and in that class there is another class. Those. I emphasize once again: Everything is just like in real life - a sentence in a paragraph, words in a sentence. And here: the class sentence in the class paragraph , and in the class sentence class word , etc.