From 46d339f31e1848b2d9bff61e07a951b2e389c69a Mon Sep 17 00:00:00 2001 From: Rhinemann Date: Mon, 5 Jun 2023 17:11:49 +0300 Subject: [PATCH] Lab 5, progress. --- Java/lab_5/Punctuation.kt | 4 ++++ Java/lab_5/Sentence.kt | 10 +++++++++- Java/lab_5/Word.kt | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Java/lab_5/Punctuation.kt b/Java/lab_5/Punctuation.kt index fb4a96c..b58913c 100644 --- a/Java/lab_5/Punctuation.kt +++ b/Java/lab_5/Punctuation.kt @@ -8,4 +8,8 @@ class Punctuation(var punctuationMark: String) { this.punctuationMark = "" } } + + override fun toString(): String { + return punctuationMark + } } \ No newline at end of file diff --git a/Java/lab_5/Sentence.kt b/Java/lab_5/Sentence.kt index 5f52977..ba3da6a 100644 --- a/Java/lab_5/Sentence.kt +++ b/Java/lab_5/Sentence.kt @@ -1,4 +1,12 @@ package OOP.Java.lab_5 -class Sentence { +class Sentence(sentenceString: String) { + init { + var split = sentenceString.split("(\\p{Punct}? )|(\\p{Punct})".toRegex()) + var punctuation: Array = sentenceString.split(" ").map { word -> Punctuation(word.last().toString()) }.toTypedArray() + for (elem in split) { + println(elem) + } + print(split) + } } \ No newline at end of file diff --git a/Java/lab_5/Word.kt b/Java/lab_5/Word.kt index beb3ee4..a857ecb 100644 --- a/Java/lab_5/Word.kt +++ b/Java/lab_5/Word.kt @@ -9,5 +9,5 @@ class Word(var letters: Array) { } constructor( word: String - ) : this((word.toCharArray().map { n -> Letter(n) }).toTypedArray()) + ) : this((word.toCharArray().map { letter -> Letter(letter) }).toTypedArray()) } \ No newline at end of file