Compare commits

...

5 Commits

Author SHA1 Message Date
Oleksii Aleshchenko f05125e298
Merge pull request #3 from Dymik739/commit-fix
Lab2: remove duplicate string to fix calculations
2023-05-11 16:12:29 +03:00
Oleksii Aleshchenko ce73ebf1f5 update lab4 2023-05-11 16:10:42 +03:00
Oleksii Aleshchenko 31c3b96018 update Variant0.java 2023-05-11 15:46:43 +03:00
dymik739 4eecffe040 Merge branch 'master' into commit-fix 2023-05-04 18:06:15 +03:00
dymik739 ae042010a6 remove duplicate string to fix calculations 2023-05-02 18:48:21 +03:00
4 changed files with 121 additions and 4 deletions

View File

@ -107,7 +107,6 @@ public class Lab2 {
valueRepeats = true;
}
}
sum += tmpSmallest;
if (!valueRepeats) {
sum += tmpSmallest;

View File

@ -1,17 +1,65 @@
package lab3;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/**
* Знайти найбільшу кількість речень заданого тексту, в яких є однакові слова.
*/
public class Variant0 {
public static void main(String[] args) {
String textString = "A, a. B a. B a. B a. C.";
final String[] sentencesStrings = textString.split("\\. ?");
System.out.println("\\");
String textString = "Aa, a b. Bb a? B a! B a. Ccc.";
// final String[] sentencesStrings = textString.split("(?<=(\\.|!|\\?)) ");
// final String[] sentencesStrings = textString.split("(?<=[.!?]) ");
final String[] sentencesStrings = textString.split("[.!?] ?");
for (String sentencesString : sentencesStrings) {
System.out.println(sentencesString);
System.out.println("[" + sentencesString + "]");
}
System.out.println("++++++++++++");
final String[][] wordsStringsBySentences = new String[sentencesStrings.length][];
for (int i = 0; i < sentencesStrings.length; i++) {
wordsStringsBySentences[i] = sentencesStrings[i].split(",? ");
}
for (String[] wordsStrings : wordsStringsBySentences) {
for (String wordsString : wordsStrings) {
System.out.print("[" + wordsString + "] - ");
}
System.out.println();
}
Set<String> originalWordsStrings = new HashSet();
for (String[] wordsStrings : wordsStringsBySentences) {
for (String wordsString : wordsStrings) {
originalWordsStrings.add(wordsString.toLowerCase());
}
}
final String[] originalWordsArray = originalWordsStrings.toArray(new String[0]);
System.out.println("++++++++++++");
for (Object originalWordsString : originalWordsStrings) {
System.out.println(originalWordsString);
}
int[] entersQuantitiesOriginalWordsInSentences = new int[originalWordsArray.length];
for (int i = 0; i < originalWordsArray.length; i++) {
String originalWord = originalWordsArray[i];
for (String[] words : wordsStringsBySentences) {
for (String word : words) {
if (originalWord.equalsIgnoreCase(word)) {
entersQuantitiesOriginalWordsInSentences[i]++;
break;
}
}
}
}
// todo show greatest value from entersQuantitiesOriginalWordsInSentences
// System.out.println(Arrays.toString(sentencesStrings));
System.out.println("++++++++++++");
}

55
src/lab4/Furniture.java Normal file
View File

@ -0,0 +1,55 @@
package lab4;
/**
* My class Furniture.
*/
public class Furniture {
/**
*
*/
private String material;
private int length;
private int height;
private int width;
private int price;
/**
*
* @param material
* @param length
* @param height
* @param width
* @param price
*/
public Furniture(String material, int length, int height, int width, int price) {
this.material = material;
this.length = length;
this.height = height;
this.width = width;
this.price = price;
}
public String getMaterial() {
return material;
}
public int getLength() {
return length;
}
public int getHeight() {
return height;
}
public int getWidth() {
return width;
}
public int getPrice() {
return price;
}
/*public Furniture() {
}*/
}

View File

@ -1,7 +1,22 @@
package lab4;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
//todo equals+hashcode
// todo JavaDoc
Furniture[] furnitureArray = {
new Furniture("A", 1, 1, 1, 1),
new Furniture("D", 1, 1, 1, 4),
new Furniture("B", 1, 2, 1, 1),
new Furniture("C", 1, 1, 3, 1),
};
Arrays.sort(furnitureArray, (o1, o2) -> o1.getMaterial().compareTo(o2.getMaterial()));
// todo print
// todo check
Arrays.sort(furnitureArray, (o1, o2) -> Integer.compare(o2.getPrice(), o1.getPrice()));
}
}