Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/main/kotlin/AbstractKlass/abstractclass.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package AbstractKlass

// Базовый абстрактный класс Shape
abstract class Shape {
// Абстрактный метод для вычисления площади фигуры
abstract fun calculateArea(): Double
}

// Подкласс Circle, представляющий круг
class Circle(val radius: Double) : Shape() {
// Переопределите метод calculateArea(), чтобы он возвращал площадь круга
override fun calculateArea(): Double {
return Math.PI * radius * radius
}
}

// Подкласс Rectangle, представляющий прямоугольник
class Rectangle(val width: Double, val height: Double) : Shape() {
// Переопределите метод calculateArea(), чтобы он возвращал площадь прямоугольника
override fun calculateArea(): Double {
return width * height
}
}

fun main() {
// Создайте экземпляр круга и прямоугольника
val circle = Circle(5.0)
val rectangle = Rectangle(4.0, 6.0)

// Выведите площади фигур
println("Площадь круга: ${circle.calculateArea()}")
println("Площадь прямоугольника: ${rectangle.calculateArea()}")
}
2 changes: 2 additions & 0 deletions src/main/kotlin/Demo1.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Demo1 {
}
4 changes: 4 additions & 0 deletions src/main/kotlin/Nasledovanie/avto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package Nasledovanie

class avto {
}
38 changes: 38 additions & 0 deletions src/main/kotlin/Personal/Department.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package Personal

class Department(private var _name: String, private var _employees: List<String>) {

var name: String
get() = _name
set(value) {
_name = value
}

var employees: List<String>
get() = _employees
set(value) {
if (value.isNotEmpty()) {
_employees = value
} else {
println("Список сотрудников не может быть пустым.")
}
}
}

fun main() {
val department = Department("IT", listOf("Алиса", "Дима"))

println(department.name) // Output: IT
println(department.employees) // Output: [Alice, Bob]

// Попытка установить пустой список сотрудников
department.employees = listOf()
// Output: Список сотрудников не может быть пустым.

// Список сотрудников остается прежним
println(department.employees) // Output: [Alice, Bob]

// Устанавливаем новый непустой список сотрудников
department.employees = listOf("Андрей", "Мишка")
println(department.employees) // Output: [Charlie, Dave]
}
67 changes: 67 additions & 0 deletions src/main/kotlin/nasledovanie/avto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package Nasledovanie

class avto {
}

abstract class Vehicle(val speed: Int, val color: String) {
abstract fun makeSound()

open fun displayInfo() {
println("Транспортное средство: ${this::class.simpleName}")
println("Скорость: $speed")
println("Цвет: $color")
}
}

class Bike(speed: Int, color: String, val countOfWheels: Int) : Vehicle(speed, color) {
override fun makeSound() {
println("Звонок велосипеда")
}

override fun displayInfo() {
super.displayInfo()
println("Количество колес: $countOfWheels")
}
}

class ElectricCar(speed: Int, color: String, val batteryCapacity: Int) : Vehicle(speed, color) {
override fun makeSound() {
println("Звук гудка электромобиля")
}

override fun displayInfo() {
super.displayInfo()
println("Емкость аккумулятора: $batteryCapacity")
}
}

interface FuelEfficient {
fun fuelEfficiency()
}

class Car(speed: Int, color: String) : Vehicle(speed, color), FuelEfficient {
override fun makeSound() {
println("Звук гудка автомобиля")
}

override fun fuelEfficiency() {
println("Автомобиль - эффективное использование топлива")
}
}

fun main() {
val vehicles = listOf(
Car(100, "красный"),
Bike(30, "синий", 2),
ElectricCar(80, "зеленый", 100)
)

for (vehicle in vehicles) {
vehicle.displayInfo()
vehicle.makeSound()
if (vehicle is FuelEfficient) {
vehicle.fuelEfficiency()
}
println()
}
}
6 changes: 6 additions & 0 deletions src/main/kotlin/one/Bike.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package one

class Bike : Vehicle() {


}
65 changes: 65 additions & 0 deletions src/main/kotlin/polemorfizm/DiagramClass.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package polemorfizm

class DiagramClass {
}

//Диаграмма 1
open class Click { }
class Clack : Click() { }


//Диаграмма 2
open class Top { }
class Tip : Top() { }


//Диаграмма 3
abstract class Alpha { }
class Omega : Alpha() { }


//Диаграмма 4
open class Foo { }
open class Bar : Foo() { }
class Baz : Bar() { }


//Диаграмма 5
interface Fi { }
open class Fee : Fi { }
class Fo : Fee() { }
class Fum : Fo() { }

//2-е Задание
interface Flyable{
val x:String
fun fly(){
println("$x is flying")
}
}

class Bird : Flyable{
override val x="Bird"
}

class Plane : Flyable{
override val x="Plane"
}
class Superhero : Flyable{
override val x="Superhero"
}

fun main(args: Array<String>){
val f= arrayOf(Bird(),Plane(),Superhero())
var x=0
while (x in 0..2){
when(f[x]){
is Bird->{
x++
f[x].fly()
}
is Plane,is Superhero->f[x].fly()
}
x++
}
}