mirror of
https://github.com/ASDjonok/OOP_IO-2x_2023.git
synced 2025-06-07 22:49:24 +03:00
lab5 & update lab4
This commit is contained in:
parent
dbe4b8119c
commit
77e8f72f79
8
lab4/.idea/.gitignore
generated
vendored
Normal file
8
lab4/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
9
lab4/.idea/lab4.iml
generated
Normal file
9
lab4/.idea/lab4.iml
generated
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
8
lab4/.idea/modules.xml
generated
Normal file
8
lab4/.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/lab4.iml" filepath="$PROJECT_DIR$/.idea/lab4.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
lab4/.idea/vcs.xml
generated
Normal file
6
lab4/.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
BIN
lab5/lab5.pdf
Normal file
BIN
lab5/lab5.pdf
Normal file
Binary file not shown.
8
lab5/untitled/.idea/.gitignore
generated
vendored
Normal file
8
lab5/untitled/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
6
lab5/untitled/.idea/misc.xml
generated
Normal file
6
lab5/untitled/.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
lab5/untitled/.idea/modules.xml
generated
Normal file
8
lab5/untitled/.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/untitled.iml" filepath="$PROJECT_DIR$/untitled.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
BIN
lab5/untitled/out/production/untitled/Letter.class
Normal file
BIN
lab5/untitled/out/production/untitled/Letter.class
Normal file
Binary file not shown.
BIN
lab5/untitled/out/production/untitled/Main.class
Normal file
BIN
lab5/untitled/out/production/untitled/Main.class
Normal file
Binary file not shown.
BIN
lab5/untitled/out/production/untitled/Sentence.class
Normal file
BIN
lab5/untitled/out/production/untitled/Sentence.class
Normal file
Binary file not shown.
BIN
lab5/untitled/out/production/untitled/Text.class
Normal file
BIN
lab5/untitled/out/production/untitled/Text.class
Normal file
Binary file not shown.
BIN
lab5/untitled/out/production/untitled/TextProcessor.class
Normal file
BIN
lab5/untitled/out/production/untitled/TextProcessor.class
Normal file
Binary file not shown.
BIN
lab5/untitled/out/production/untitled/Word.class
Normal file
BIN
lab5/untitled/out/production/untitled/Word.class
Normal file
Binary file not shown.
166
lab5/untitled/src/Main.java
Normal file
166
lab5/untitled/src/Main.java
Normal file
@ -0,0 +1,166 @@
|
||||
import java.util.HashSet;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String inputText = "Раз два три, літо прийди! По ООП сто балів захвати. ім'я запише без апострофу, ех"; //вход даних, текст
|
||||
int targetLength = 3; //змінна, кількість літер в слові
|
||||
|
||||
try {
|
||||
TextProcessor textProcessor = new TextProcessor();
|
||||
HashSet<Word> uniqueWords = textProcessor.findUniqueWordsWithLength(inputText, targetLength);
|
||||
System.out.println("Unique words of length " + targetLength + " in the input text are: " + uniqueWords);// вивод повідомлення, що містить довжину та унікальні слова змінної
|
||||
} catch (Exception e) {
|
||||
System.out.println("An error occurred: " + e.getMessage());//вивиод помилки
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Letter {
|
||||
private char value;
|
||||
|
||||
public Letter(char value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public char getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(char value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
class Word {
|
||||
private Letter[] letters;
|
||||
|
||||
public Word(Letter[] letters) {
|
||||
this.letters = letters;
|
||||
}
|
||||
|
||||
public Letter[] getLetters() {
|
||||
return letters;
|
||||
}
|
||||
|
||||
public void setLetters(Letter[] letters) {
|
||||
this.letters = letters;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return letters.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Letter letter : letters) {
|
||||
sb.append(letter.getValue());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Word other = (Word) obj;
|
||||
return this.toString().equals(other.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.toString().hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
class Sentence {
|
||||
private Word[] words;
|
||||
private String punctuation;
|
||||
|
||||
public Sentence(Word[] words, String punctuation) {
|
||||
this.words = words;
|
||||
this.punctuation = punctuation;
|
||||
}
|
||||
|
||||
public Word[] getWords() {
|
||||
return words;
|
||||
}
|
||||
|
||||
public void setWords(Word[] words) {
|
||||
this.words = words;
|
||||
}
|
||||
|
||||
public String getPunctuation() {
|
||||
return punctuation;
|
||||
}
|
||||
|
||||
public void setPunctuation(String punctuation) {
|
||||
this.punctuation = punctuation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Word word : words) {
|
||||
sb.append(word.toString()).append(" ");
|
||||
}
|
||||
sb.append(punctuation);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class Text {
|
||||
private Sentence[] sentences;
|
||||
|
||||
public Text(Sentence[] sentences) {
|
||||
this.sentences = sentences;
|
||||
}
|
||||
|
||||
public Sentence[] getSentences() {
|
||||
return sentences;
|
||||
}
|
||||
|
||||
public void setSentences(Sentence[] sentences) {
|
||||
this.sentences = sentences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Sentence sentence : sentences) {
|
||||
sb.append(sentence.toString());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class TextProcessor {
|
||||
public HashSet<Word> findUniqueWordsWithLength(String inputText, int targetLength) {
|
||||
HashSet<Word> uniqueWords = new HashSet<>();
|
||||
String[] sentenceStrings = inputText.split("[?]");
|
||||
for (String sentenceString : sentenceStrings) {
|
||||
String[] wordStrings = sentenceString.trim().split("\\s+");
|
||||
for (String wordString : wordStrings) {
|
||||
wordString = wordString.replaceAll("[\\t\\s]+", " "); // Заміна послідовності табуляцій та пробілів одним пробілом
|
||||
wordString = wordString.replaceAll("[^\\p{L}\\s]", ""); // Вилучення розділових знаків
|
||||
wordString = wordString.toLowerCase(); // Перетворення на нижній регістр
|
||||
wordString = wordString.replace("’", ""); // Вилучення апострофів
|
||||
|
||||
if (wordString.length() == targetLength) {
|
||||
Letter[] letters = new Letter[wordString.length()];
|
||||
for (int i = 0; i < wordString.length(); i++) {
|
||||
letters[i] = new Letter(wordString.charAt(i));
|
||||
}
|
||||
Word word = new Word(letters);
|
||||
uniqueWords.add(word);
|
||||
}
|
||||
}
|
||||
}
|
||||
return uniqueWords;
|
||||
}
|
||||
}
|
11
lab5/untitled/untitled.iml
Normal file
11
lab5/untitled/untitled.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
Loading…
x
Reference in New Issue
Block a user