Skip to content

Instantly share code, notes, and snippets.

@tipochka
Created September 30, 2016 23:37
Show Gist options
  • Save tipochka/fe3b27ec6ca735f298307307030a506d to your computer and use it in GitHub Desktop.
Save tipochka/fe3b27ec6ca735f298307307030a506d to your computer and use it in GitHub Desktop.
Блинов. Глава 4. Вариант А. 1 (*). Создать объект класса Текст, используя классы Предложение, Слово. Методы: дополнить текст, вывести на консоль текст, заголовок текста.
public class Phrase {
private String value="";
public void addValue(Word word) {
value += " " + word.getValue();
}
public String getValue() {
return value;
}
}
public class Text {
private String header;
private String body = "";
public Text(Word word) {
header = word.getValue();
}
public Text(Phrase phrase) {
header = phrase.getValue();
}
public String getHeader() {
return header;
}
public void addBody(Word word) {
body += " " + word.getValue();
}
public void addBody(Phrase phrase) {
body += " " + phrase.getValue();
}
public String getBody() {
return body;
}
}
public class TextRunner {
public static void main(String[] args) {
Word word = new Word("quote");
Text text = new Text(word);
Word word1 = new Word("quote's");
Word word2 = new Word("Les");
Word word3 = new Word("Brawn");
Phrase phrase = new Phrase();
phrase.addValue(word1);
phrase.addValue(word2);
phrase.addValue(word3);
text.addBody(phrase);
System.out.println("Head: "+text.getHeader());
System.out.println("Body: "+text.getBody());
}
}
public class Word {
private String value;
public Word(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment