Created
September 30, 2016 23:37
-
-
Save tipochka/fe3b27ec6ca735f298307307030a506d to your computer and use it in GitHub Desktop.
Блинов. Глава 4. Вариант А. 1 (*). Создать объект класса Текст, используя классы Предложение, Слово. Методы: дополнить текст, вывести на консоль текст, заголовок текста.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Phrase { | |
private String value=""; | |
public void addValue(Word word) { | |
value += " " + word.getValue(); | |
} | |
public String getValue() { | |
return value; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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