Compare commits

..

52 Commits

Author SHA1 Message Date
Rhinemann d91c576ab3 Lab 5, technically working prototype. It's horrid, though. 2023-06-05 21:47:08 +03:00
Rhinemann 49dfcfe457 Lab 5, technically working prototype. It's horrid, though. 2023-06-05 21:46:40 +03:00
Rhinemann 8e430b94ae Lab 5, progress. 2023-06-05 19:05:22 +03:00
Rhinemann 46d339f31e Lab 5, progress. 2023-06-05 17:11:49 +03:00
Rhinemann 2ddeaab94f Lab 5, started. 2023-06-05 16:37:37 +03:00
Rhinemann 2b8f88a45f Lab 3, cosmetic. 2023-06-05 16:37:15 +03:00
Rhinemann 97b2b761e4 Lab 4, Kotlin. 2023-05-17 08:35:12 +03:00
Rhinemann 4d538d2d04 Lab 4, Kotlin. 2023-05-13 14:31:07 +03:00
Rhinemann 5f36bd41ae Upd. 2023-05-08 13:36:12 +03:00
Rhinemann 499efa9c78 Upd. 2023-05-08 13:17:02 +03:00
Rhinemann 2c8c807c01 Upd. 2023-05-08 13:15:26 +03:00
Rhinemann 100398953a Slight rehash. 2023-05-08 10:53:20 +03:00
Rhinemann 0d5e3d5ffe Slight rehash. 2023-05-08 10:51:54 +03:00
Rhinemann fd8c37c7cb Slight rehash. 2023-05-08 10:48:22 +03:00
Rhinemann a8cbadbe7d Added a Kotlin variation. 2023-05-07 23:15:50 +03:00
Rhinemann 64c9e43742 Added a Kotlin variation. 2023-05-07 23:15:28 +03:00
Rhinemann 5ca9ab6c17 Added a Kotlin variation. 2023-05-07 23:14:50 +03:00
Rhinemann a97f742be2 Added a Kotlin variation. 2023-05-07 23:14:24 +03:00
Rhinemann 2494bea36c Camel case. 2023-05-07 22:20:31 +03:00
Rhinemann ca2b85ef9e . 2023-05-07 17:09:03 +03:00
Rhinemann 77f96fafa6 Working model of Lab 3. 2023-05-07 17:07:56 +03:00
Rhinemann 084f131c90 . 2023-05-07 16:46:18 +03:00
Rhinemann 197426e266 Initial lab 3. 2023-05-07 15:19:23 +03:00
Rhinemann 661c3641a1 Naming changes. 2023-05-07 15:19:06 +03:00
Rhinemann fc5704dd15 Cargo.toml added release profile. 2023-05-07 14:08:43 +03:00
Rhinemann 45ef70b268 Finished lab_1 in Rust. 2023-05-07 09:26:25 +03:00
Rhinemann fe97b8dcde . 2023-05-06 23:56:34 +03:00
Rhinemann 5c8d2bb8a1 . 2023-05-06 23:55:52 +03:00
Rhinemann 6b6076f56c Merge branch 'ІО-23/30-Швед-Андрій-Дмитрович' of https://github.com/ASDjonok/OOP_IO-2x_2023 into ІО-23/30-Швед-Андрій-Дмитрович 2023-05-06 23:50:25 +03:00
Rhinemann 9b08eb0dfc . 2023-05-06 23:50:22 +03:00
Rhinemann 9cce8b222e Delete Rust/lab_1/target directory 2023-05-06 23:47:52 +03:00
Rhinemann 74209977bc . 2023-05-06 23:44:34 +03:00
Rhinemann 83b275cefd . 2023-05-06 23:18:57 +03:00
Rhinemann af7af4d6f2 . 2023-05-06 23:09:06 +03:00
Rhinemann a4a3e09735 Lab 1. 2023-05-03 10:40:04 +03:00
Rhinemann acc2d533cb modified: Java/Lab 2/Lab_2.java 2023-05-03 10:39:06 +03:00
Rhinemann 8013099c36 All sorts of corrections. 2023-05-03 10:32:23 +03:00
Rhinemann 8100129706 Ceanup. 2023-05-02 11:42:37 +03:00
Rhinemann 83d98b2982 Merge branch 'ІО-23/30-Швед-Андрій-Дмитрович' of https://github.com/ASDjonok/OOP_IO-2x_2023 into ІО-23/30-Швед-Андрій-Дмитрович 2023-05-02 11:40:28 +03:00
Rhinemann 4af0ab5655 . 2023-05-02 11:38:55 +03:00
Rhinemann 07e9fbdc88 Delete Lab_2.class 2023-05-02 11:35:28 +03:00
Rhinemann 41aaaf4623 Delete Lab_1.class 2023-05-02 11:35:16 +03:00
Rhinemann 99e9428dba Moved folders. 2023-05-02 11:34:34 +03:00
Rhinemann fe36219746 Update Lab 1. 2023-05-02 09:58:31 +03:00
Rhinemann 896fc1f4d4 Minor cleanup 2023-04-26 14:37:46 +03:00
Rhinemann 7fa667cb2d Changes 2023-04-26 14:34:13 +03:00
Rhinemann 74a44852af Add Lab 2 2023-03-23 09:10:55 +02:00
Rhinemann 75112d90c2 Delete OOP_IO-2x_2023.iml 2023-03-23 08:59:27 +02:00
Rhinemann e21575fa93 Delete .gitignore 2023-03-23 08:59:19 +02:00
Rhinemann cf3d055f64 Delete src directory 2023-03-23 08:57:30 +02:00
Rhinemann bdf5611f46 Delete .idea directory 2023-03-23 08:57:03 +02:00
Rhinemann 80de92fa1e Lab 1 commit 2023-03-22 17:02:31 +02:00
18 changed files with 444 additions and 2 deletions
-2
View File
@@ -1,2 +0,0 @@
# Project exclude paths
/out/
+33
View File
@@ -0,0 +1,33 @@
package OOP.Java.lab_1;
import java.util.Scanner;
public class lab_1 {
public static int protectedInput(String variableToRead, Scanner input) {
do {
try {
System.out.printf("Enter %s: ", variableToRead);
return input.nextInt();
} catch (Exception e) {
System.out.printf("%s must be an integer.\n", variableToRead.toUpperCase());
input.nextLine();
}
} while (true);
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
final int n = protectedInput("n", input);
final int m = protectedInput("m", input);
final int a = protectedInput("a", input);
final int b = protectedInput("b", input);
input.close();
final float s = ((float) (b + m) / 2) * (m - b + 1) * (n - a + 1);
System.out.println("S = " + s);
}
}
+23
View File
@@ -0,0 +1,23 @@
package OOP.Java.lab_1
fun protectedInput(variableName: String): Int {
do {
try {
print("Enter $variableName: ")
return readln().toInt()
} catch (e: Exception) {
println("${variableName.uppercase()} must be an integer!")
}
} while (true)
}
fun main() {
val n: Int = protectedInput("n")
val m: Int = protectedInput("m")
val a: Int = protectedInput("a")
val b: Int = protectedInput("b")
val s: Float = (b + m).toFloat() / 2 * (m - b + 1) * (n - a + 1)
println("S = $s")
}
+104
View File
@@ -0,0 +1,104 @@
package OOP.Java.lab_2;
import java.util.Scanner;
public class lab_2 {
public static short protectedInput(String inputPrompt, String errorMessage, Scanner input) {
short read_variable;
do {
try {
System.out.println();
System.out.print(inputPrompt);
read_variable = input.nextShort();
break;
} catch (Exception e) {
System.out.println(errorMessage);
input.nextLine();
}
} while (true);
return read_variable;
}
public static String format(int number) {
int width = String.valueOf(number).length() + 1;
return "|%" + width + "d ";
}
public static double average(short[] row) {
short sum = 0;
for (short element : row) {
sum += element;
}
return (double) sum / row.length;
}
public static void main(String[] args) {
short rows, columns;
Scanner input = new Scanner(System.in);
final short a = protectedInput("Input a constant to multiply a matrix by: ",
"A constant must be a short-data type integer, try again.", input);
System.out.println();
System.out.println("Input size of the matrix.");
do {
rows = protectedInput("Rows: ",
"A number of rows must be a short-data type integer, try again.", input);
} while (rows <= 0);
do {
columns = protectedInput("Columns: ",
"A number of columns must be a short-data type integer, try again.", input);
} while (columns <= 0);
input.close();
short[][] matrix_B = new short[rows][columns];
System.out.println();
System.out.println("Matrix B:");
String format = format(rows * columns);
for (short i = 0; i < rows; i++) {
for (short j = 0; j < columns; j++) {
matrix_B[i][j] = (short) ((i + 1) * (j + 1));
System.out.printf(format, matrix_B[i][j]);
}
System.out.println("|");
}
System.out.println();
System.out.println("Matrix a×B:");
format = format(rows * columns * a);
for (short i = 0; i < matrix_B.length; i++) {
for (short j = 0; j < matrix_B[i].length; j++) {
matrix_B[i][j] *= (a);
System.out.printf(format, matrix_B[i][j]);
}
System.out.println("|");
}
System.out.println();
System.out.println("Averages of each row:");
for (short[] row : matrix_B) {
System.out.println(average(row));
}
}
}
+57
View File
@@ -0,0 +1,57 @@
package OOP.Java.lab_3;
public class lab_3 {
static int maxStrLength;
static String result;
public static void cSubUtil(StringBuilder stringbuilder, int leftBoundary, int rightBoundary) {
String string = stringbuilder.toString().toLowerCase().replaceAll("[^a-z]","");
// check if the indices lie in the range of string
// and also if it is palindrome
while (leftBoundary >= 0 && rightBoundary < string.length() && string.toLowerCase().charAt(leftBoundary) == string.toLowerCase().charAt(rightBoundary)) {
// expand the boundary
leftBoundary--;
rightBoundary++;
}
// if it's length is greater than maxStrLength update
// maxLength and result
if (rightBoundary - leftBoundary - 1 >= maxStrLength) {
result = string.substring(leftBoundary + 1, rightBoundary);
maxStrLength = rightBoundary - leftBoundary - 1;
}
}
public static int longestPalSubstr(StringBuilder string)
{
result = "";
maxStrLength = 1;
// for every index in the string check palindromes
// starting from that index
for (int i = 0; i < string.length(); i++) {
// check for odd length palindromes
cSubUtil(string, i, i);
// check for even length palindromes
cSubUtil(string, i, i + 1);
}
System.out.println("Longest palindrome substring is: " + compareStrings(string));
return compareStrings(string).length();
}
public static String compareStrings(StringBuilder builder) {
for (int leftBoundary = 0; leftBoundary <= builder.length(); leftBoundary++) {
for (int rightBoundary = builder.length(); rightBoundary >= leftBoundary; rightBoundary--) {
if (result.equals(builder.substring(leftBoundary, rightBoundary).toLowerCase().replaceAll("[^a-z]",""))) {
return builder.substring(leftBoundary, rightBoundary);
}
}
}
return "";
}
public static void main(String[] args) {
StringBuilder stringToDetect = new StringBuilder("Eva, can I see bees in a cave?");
System.out.println("Initial string: " + stringToDetect);
System.out.println("Length is: " + longestPalSubstr(stringToDetect));
}
}
+11
View File
@@ -0,0 +1,11 @@
package OOP.Java.lab_4
class Furniture(val name: String, val material: String, val price: Int, val length: Int, val width: Int, val height: Int) {
fun print(nameWidth: Int, materialWidth: Int, priceWidth: Int){
print("Furniture stats: {")
print("Name: ${this.name.padEnd(nameWidth)} ")
print("Material: ${this.material.padEnd(materialWidth)} ")
print("Price: ${(this.price.toString() + " cu").padEnd(priceWidth + 3)} ")
print("Size: ${this.length}×${this.width}×${this.height}};\n")
}
}
+26
View File
@@ -0,0 +1,26 @@
package OOP.Java.lab_4
fun main() {
val furnitureArray = arrayOf(
Furniture("Chair", "Wood", 10, 5, 5, 10),
Furniture("Counter-top", "Marble", 1_000, 10, 5, 1),
Furniture("Dinner table", "Glass", 500, 15, 10, 1),
Furniture("Office table", "Wood", 200, 10, 7, 1),
Furniture("Refrigerator", "Stainless steel", 20_000, 8, 4, 10)
)
val maxNameWidth = furnitureArray.maxWith(Comparator.comparingInt { it.name.length }).name.length
val maxMaterialWidth = furnitureArray.maxWith(Comparator.comparingInt { it.material.length }).material.length
val maxPriceWidth = furnitureArray.maxWith(Comparator.comparingInt { it.price }).price.toString().length
println("\nUnsorted array:")
for (item in furnitureArray) item.print(maxNameWidth, maxMaterialWidth, maxPriceWidth)
println("\nSorted alphabetically by name:")
furnitureArray.sortBy { it.name }
for (item in furnitureArray) item.print(maxNameWidth, maxMaterialWidth, maxPriceWidth)
println("\nSorted alphabetically by material:")
furnitureArray.sortBy { it.material }
for (item in furnitureArray) item.print(maxNameWidth, maxMaterialWidth, maxPriceWidth)
}
+11
View File
@@ -0,0 +1,11 @@
package OOP.Java.lab_5
class Letter(val character: Char) {
override fun toString(): String {
return this.character.toString()
}
fun equals(letter: Letter, ignoreCase: Boolean): Boolean {
return this.character.toString().equals(letter.toString(), ignoreCase)
}
}
+15
View File
@@ -0,0 +1,15 @@
package OOP.Java.lab_5
class Punctuation(var punctuationMark: String) {
private val punctuationMarkOptions: Regex = Regex("\\p{Punct}")
init {
if (!punctuationMarkOptions.containsMatchIn(punctuationMark)) {
this.punctuationMark = ""
}
}
override fun toString(): String {
return punctuationMark
}
}
+31
View File
@@ -0,0 +1,31 @@
package OOP.Java.lab_5
class Sentence(sentenceString: String) {
var sentenceArray = arrayOf<Pair<Word, Punctuation>>()
val arrayOfWords: Array<Word> = splitWords(sentenceString)
val arrayOfPunctuations: Array<Punctuation> = splitPunctuation(sentenceString)
init {
// val arrayOfWords: Array<Word> = splitWords(sentenceString)
// val arrayOfPunctuations: Array<Punctuation> = splitPunctuation(sentenceString)
for (i in arrayOfWords.indices) {
sentenceArray += Pair(arrayOfWords[i], arrayOfPunctuations[i])
}
}
private fun splitWords(sentenceString: String): Array<Word> {
return sentenceString.split("[\\p{Punct}\\s]+".toRegex()).filter { it.isNotEmpty() }.map { word -> Word(word) }.toTypedArray()
}
private fun splitPunctuation(sentenceString: String): Array<Punctuation> {
return sentenceString.split(" ").map { word -> Punctuation(word.last().toString()) }.toTypedArray()
}
override fun toString(): String {
var sentence = arrayOf<String>()
this.sentenceArray.forEach { sentence += it.first.toString() + it.second.toString() }
return sentence.joinToString(" ")
}
}
+55
View File
@@ -0,0 +1,55 @@
package OOP.Java.lab_5
class Text(textString: String) {
var textArray = arrayOf<Pair<Sentence, Punctuation>>()
var rawText: String = ""
// val arrayOfSentences = splitSentences(textString)
// val arrayOfPunctuations: Array<Punctuation> = splitPunctuation(textString)
init {
val arrayOfSentences = splitSentences(textString)
val arrayOfPunctuations: Array<Punctuation> = splitPunctuation(textString)
for (i in arrayOfSentences.indices) {
textArray += Pair(arrayOfSentences[i], arrayOfPunctuations[i])
}
this.rawText = getRawTextString(arrayOfSentences)
}
private fun splitSentences(textString: String): Array<Sentence> {
return textString.split("[.!?] ?".toRegex()).filter { it.isNotEmpty() }.map { sentence -> Sentence(sentence) }.toTypedArray()
}
private fun splitPunctuation(textString: String): Array<Punctuation> {
return textString.split("(?<=[.!?]) ?".toRegex()).filter { it.isNotEmpty() }.map { sentence -> Punctuation(sentence.last().toString()) }.toTypedArray()
}
private fun getRawTextString(arrayOfSentences: Array<Sentence>): String {
return arrayOfSentences.joinToString("") { sentence -> sentence.arrayOfWords.joinToString("") }
}
fun palindromeSearch(): String {
var results = arrayOf<String>()
for (leftBoundary in 0 until this.rawText.length) {
for (rightBoundary in this.rawText.length downTo leftBoundary + 1) {
val subToC = this.rawText.substring(leftBoundary, rightBoundary)
if (subToC.first().equals(subToC.last(), true) && subToC.equals(subToC.reversed(), true) && subToC.length >= 3) {
// println(subToC)
results += subToC
}
}
}
return results.maxBy { it.length }
}
override fun toString(): String {
var text = arrayOf<String>()
this.textArray.forEach { text += it.first.toString() + it.second.toString() }
return text.joinToString(" ")
}
}
+13
View File
@@ -0,0 +1,13 @@
package OOP.Java.lab_5
class Word(var letters: Array<Letter>) {
override fun toString(): String {
val wordString = StringBuilder()
this.letters.forEach { wordString.append(it) }
return wordString.toString()
}
constructor(
word: String
) : this((word.toCharArray().map { letter -> Letter(letter) }).toTypedArray())
}
+16
View File
@@ -0,0 +1,16 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "lab_1"
version = "0.1.0"
dependencies = [
"text_io",
]
[[package]]
name = "text_io"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5f0c8eb2ad70c12a6a69508f499b3051c924f4b1cfeae85bfad96e6bc5bba46"
+9
View File
@@ -0,0 +1,9 @@
[package]
name = "lab_1"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
text_io = "0.1.12"
+22
View File
@@ -0,0 +1,22 @@
fn protected_read(variable_name: &str) -> i32 {
use text_io::try_read;
loop {
print!("Enter {}: ", variable_name);
let read_result: Result<i32, _> = try_read!();
match read_result {
Ok(read_integer) => return read_integer,
Err(_e) => println!("{} must be an integer!", variable_name.to_uppercase()),
}
}
}
fn main() {
let n: i32 = protected_read("n");
let m: i32 = protected_read("m");
let a: i32 = protected_read("a");
let b: i32 = protected_read("b");
let s: f32 = ((b + m) as f32 / 2f32) * ((m - b + 1) * (n - a + 1)) as f32;
println!("S = {}", s);
}
+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "lab_2"
version = "0.1.0"
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "lab_2"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+3
View File
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}