Compare commits

..

No commits in common. "55bfc1cca6ad5428d3340d2b349bd0d91df0c482" and "788fa03edaad0ca1cb248a8be672ef8d54181ecb" have entirely different histories.

15 changed files with 172 additions and 232 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-20" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

11
lab1/lab1.iml Normal file
View 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>

Binary file not shown.

38
lab1/src/Main.java Normal file
View File

@ -0,0 +1,38 @@
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
/* Номер залікової книжки - 2425,
C2 = 1, C3 = 1 = C,C5 = 0, C7 = 3, index's type = long */
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.##");
public static void main(String[] args) {
//System.out.println("Перед тим як вводити значення враховуйте умову: 0 < a <= n\n 0 <= b <= m");
System.out.print("\nВеддіть ваше значення a: ");
Scanner a1 = new Scanner(System.in);
int a = a1.nextInt();
System.out.print("\nВеддіть ваше значення b: ");
Scanner b1 = new Scanner(System.in);
int b = b1.nextInt();
System.out.print("\nВеддіть ваше значення m: ");
Scanner m1 = new Scanner(System.in);
int m = m1.nextInt();
System.out.print("\nВеддіть ваше значення n: ");
Scanner n1 = new Scanner(System.in);
int n = n1.nextInt();
double S = 0;
final int C = 1; //Const
if (b >= 0 && a <= n && b <= m && a > 1) {
for (long i = a; i <= n; i++) {
for (long j = b; j <= m; j++) {
S += (double) (i * j) / (i - C);
}
}
System.out.println("Значення S = " + DECIMAL_FORMAT.format(S));
} else {
System.out.println("Значення А має бути > 0\nЗначення А має бути <= n");
System.out.println("Значення B має бути >= 0\nЗначення B має бути <= m");
}
}
}

View File

@ -1,231 +0,0 @@
import java.util.ArrayList;
import java.util.List;
class Letter {
private char character;
public Letter(char character) {
this.character = character;
}
public char getCharacter() {
return character;
}
@Override
public String toString() {
return String.valueOf(character);
}
}
class Word {
private List<Letter> letters;
public Word(List<Letter> letters) {
this.letters = letters;
}
public List<Letter> getLetters() {
return letters;
}
@Override
public String toString() {
StringBuilder wordBuilder = new StringBuilder();
for (Letter letter : letters) {
wordBuilder.append(letter.getCharacter());
}
return wordBuilder.toString();
}
}
class Sentence {
private List<Object> components;
public Sentence(List<Object> components) {
this.components = components;
}
public List<Object> getComponents() {
return components;
}
@Override
public String toString() {
StringBuilder sentenceBuilder = new StringBuilder();
for (Object component : components) {
if (component instanceof Word) {
List<Letter> letters = ((Word) component).getLetters();
for (Letter letter : letters) {
sentenceBuilder.append(letter.getCharacter());
}
} else if (component instanceof PunctuationMark) {
sentenceBuilder.append(((PunctuationMark) component).getMark());
}
sentenceBuilder.append(" ");
}
return sentenceBuilder.toString().trim();
}
}
class PunctuationMark {
private char mark;
public PunctuationMark(char mark) {
this.mark = mark;
}
public char getMark() {
return mark;
}
@Override
public String toString() {
return String.valueOf(mark);
}
}
class Text {
private List<Sentence> sentences;
public Text(List<Sentence> sentences) {
this.sentences = sentences;
}
public List<Sentence> getSentences() {
return sentences;
}
@Override
public String toString() {
StringBuilder textBuilder = new StringBuilder();
for (Sentence sentence : sentences) {
textBuilder.append(sentence.toString()).append(". ");
}
return textBuilder.toString().trim();
}
}
public class Lab5 {
public static void main(String[] args) {
System.out.println("C17 = " + 2425%17);
StringBuffer sentence = new StringBuffer("об'єктно-орієнтована мова програмування , випущена 1995 року компанією" +
" Сан Майкросістемс , як основний компонент платформи Джава." +
" З 2009 року мовою займається компанія Оракл , яка того року придбала Сан Майкросістемс. В офіційній" +
" реалізації Джава-програми компілюються у байт-код , який при виконанні інтерпретується віртуальною" +
" машиною для конкретної платформи");
// Заміна послідовності табуляцій та пробілів одним пробілом
String cleanedText = replaceTabsAndSpaces(sentence.toString());
// Розбиття тексту на речення
String[] sentenceArray = cleanedText.split("\\.");
List<Sentence> sentences = new ArrayList<>();
List<Character> punctuationMarks = new ArrayList<>();
for (String s : sentenceArray) {
// Розбиття речення на слова та розділові знаки
String[] components = s.trim().split("\\s+");
List<Object> sentenceComponents = new ArrayList<>();
for (String component : components) {
if (isPunctuationMark(component)) {
// Додавання розділових знаків
char mark = component.charAt(component.length() - 1);
punctuationMarks.add(mark);
sentenceComponents.add(new PunctuationMark(mark));
} else {
// Створення слова
List<Letter> letters = new ArrayList<>();
for (char c : component.toCharArray()) {
letters.add(new Letter(c));
}
sentenceComponents.add(new Word(letters));
}
}
sentences.add(new Sentence(sentenceComponents));
}
// Створення тексту
Text text = new Text(sentences);
// Виведення букв, слів та речень
List<Sentence> allSentences = text.getSentences();
for (Sentence s : allSentences) {
List<Object> components = s.getComponents();
for (Object component : components) {
if (component instanceof Word) {
System.out.println("Слово: " + component);
List<Letter> letters = ((Word) component).getLetters();
for (Letter letter : letters) {
System.out.println("Літера: " + letter.getCharacter());
}
} else if (component instanceof PunctuationMark) {
System.out.println("Розділовий знак: " + ((PunctuationMark) component).getMark());
}
}
System.out.println("Речення: " + s.toString());
System.out.println();
}
// Виведення розділових знаків
System.out.println("Розділові знаки:");
for (Character mark : punctuationMarks) {
System.out.println(mark);
}
// Виведення масиву речень з пробілами
System.out.println("Масив речень:");
for (Sentence s : allSentences) {
System.out.println(s.toString());
}
// Видалення слів заданої довжини, починаючи з приголосної літери
removeWords(allSentences);
// Виведення оновленого тексту
System.out.println("Оновлений текст:");
System.out.println(text.toString());
}
// Функція для заміни табуляцій та пробілів одним пробілом
private static String replaceTabsAndSpaces(String text) {
return text.replaceAll("\\s+", " ");
}
// Функція для перевірки, чи є рядок розділовим знаком
private static boolean isPunctuationMark(String text) {
return text.matches(".*[,.]$");
}
// Функція для видалення слів заданої довжини, починаючи з приголосної літери
private static void removeWords(List<Sentence> sentences) {
String consonants = "бвгґджзклмнпрстфхцчшщ";
for (Sentence sentence : sentences) {
List<Object> components = sentence.getComponents();
List<Object> componentsToRemove = new ArrayList<>();
for (Object component : components) {
if (component instanceof Word) {
Word word = (Word) component;
List<Letter> letters = word.getLetters();
int wordLength = letters.size();
char firstLetter = letters.get(0).getCharacter();
if ((wordLength > 5) && (wordLength < 9) && consonants.contains(String.valueOf(firstLetter))) {
componentsToRemove.add(component);
}
}
}
components.removeAll(componentsToRemove);
}
}
}

15
src/Main.java Normal file
View File

@ -0,0 +1,15 @@
public class Main {
public static void main(String[] args) {
System.out.println(args[2]);
System.out.println("Hello world!");
// System.out.println(1);
}
void myFunction() {
}
int myFunction2() {
return 1;
}
}

View File

@ -0,0 +1,20 @@
package encapsulationInheritancePolymorphism;
public class Encapsulation {
/*private*/ int field;
private int field2;
// int a = 1;
public void myMethodForTheField () {
System.out.println(field);
}
public void myMethodForTheField2 () {
System.out.println(field);
}
public void myMethodForTheFieldAndTheField2 () {
System.out.println(field);
}
}

View File

@ -0,0 +1,10 @@
package encapsulationInheritancePolymorphism;
public class EncapsulationInheritancePolymorphism {
public static void main(String[] args) {
int a = 1;
// var b = 2;
// System.out.println(b);
}
}

View File

@ -0,0 +1,14 @@
package encapsulationInheritancePolymorphism;
public class Main {
public static void main(String[] args) {
Student student = new Student();
//...
student.setFaculty("FPM", "MO-22");
}
}

View File

@ -0,0 +1,18 @@
package encapsulationInheritancePolymorphism;
public class Student {
private String name;
private String surname;
private String group;
private String faculty;
public String getName() {
return name;
}
public void setFaculty(String faculty, String group) {
this.faculty = faculty;
this.group = group;
}
}

View File

@ -0,0 +1,5 @@
package encapsulationInheritancePolymorphism.inheritance;
public class ElectricEngine extends Engine {
private String batteryType;
}

View File

@ -0,0 +1,5 @@
package encapsulationInheritancePolymorphism.inheritance;
public class Engine {
private int power;
}

View File

@ -0,0 +1,7 @@
package encapsulationInheritancePolymorphism.inheritance;
public class Main {
public static void main(String[] args) {
ElectricEngine electricEngine = new ElectricEngine();
}
}

13
src/test/A.java Normal file
View File

@ -0,0 +1,13 @@
package test;
public class A {
/*private*/ int f/* = 3*/;
public int getF() {
return f;
}
public void setF(int f) {
this.f = f;
}
}

15
src/test/Main.java Normal file
View File

@ -0,0 +1,15 @@
package test;
public class Main {
public static void main(String[] args) {
A a = new A();
System.out.println(a.getF());
a.setF(1);
System.out.println(a.getF());
System.out.println(a.f);
int[] array = {1, 2, 1};
System.out.println(array.length);
}
}