From 4d538d2d04b946fbed32c330b9eaafaec9f14a6d Mon Sep 17 00:00:00 2001 From: Rhinemann Date: Sat, 13 May 2023 14:31:07 +0300 Subject: [PATCH] Lab 4, Kotlin. --- Java/lab_1/lab_1.java | 2 +- Java/lab_4/Furniture.kt | 11 +++++++++++ Java/lab_4/lab_3.kt | 26 ++++++++++++++++++++++++++ Rust/lab_2/src/main.rs | 2 +- 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 Java/lab_4/Furniture.kt create mode 100644 Java/lab_4/lab_3.kt diff --git a/Java/lab_1/lab_1.java b/Java/lab_1/lab_1.java index c530901..c935c43 100644 --- a/Java/lab_1/lab_1.java +++ b/Java/lab_1/lab_1.java @@ -1,4 +1,4 @@ -package OOP.Java.lab_1; + package OOP.Java.lab_1; import java.util.Scanner; diff --git a/Java/lab_4/Furniture.kt b/Java/lab_4/Furniture.kt new file mode 100644 index 0000000..f35a4c9 --- /dev/null +++ b/Java/lab_4/Furniture.kt @@ -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") + } +} \ No newline at end of file diff --git a/Java/lab_4/lab_3.kt b/Java/lab_4/lab_3.kt new file mode 100644 index 0000000..a600ab5 --- /dev/null +++ b/Java/lab_4/lab_3.kt @@ -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) +} \ No newline at end of file diff --git a/Rust/lab_2/src/main.rs b/Rust/lab_2/src/main.rs index e7a11a9..fbedd92 100644 --- a/Rust/lab_2/src/main.rs +++ b/Rust/lab_2/src/main.rs @@ -1,3 +1,3 @@ fn main() { println!("Hello, world!"); -} +} \ No newline at end of file