From 1550f651c3e21f5b2372e09b3528a7fe7f6f15d6 Mon Sep 17 00:00:00 2001 From: "Mikhail.Makhonin" Date: Thu, 4 Sep 2025 00:41:14 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20#1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 14 ++--- build.gradle | 23 +++++--- src/main/kotlin/ru/otus/cars/Car.kt | 5 ++ src/main/kotlin/ru/otus/cars/CarOutput.kt | 1 + src/main/kotlin/ru/otus/cars/FuelSystem.kt | 67 ++++++++++++++++++++++ src/main/kotlin/ru/otus/cars/Taz.kt | 2 + src/main/kotlin/ru/otus/cars/Vaz2107.kt | 13 ++++- src/main/kotlin/ru/otus/cars/Vaz2108.kt | 10 +++- src/main/kotlin/ru/otus/cars/main.kt | 17 +++++- 9 files changed, 134 insertions(+), 18 deletions(-) create mode 100644 src/main/kotlin/ru/otus/cars/FuelSystem.kt diff --git a/README.md b/README.md index 466cb7f..ad14ad0 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,14 @@ ### Задание 1. Создание топливной систем -- Топливная система машины будет состоять из бака(`Tank`) и горловины (`TankMouth`) -- Бак (его реализация) спрятана от пользователя машины -- Машина заправляется через горловину бака -- Горловина может принимать или бензин, или сжиженный газ -- Уровень бензина доступен водителю через интерфейс `CarOutput` (добавить метод в интерфейс) +- Топливная система машины будет состоять из бака(`Tank`) и горловины (`TankMouth`) + +- Бак (его реализация) спрятана от пользователя машины + +- Машина заправляется через горловину бака + +- Горловина может принимать или бензин, или сжиженный газ + +- Уровень бензина доступен водителю через интерфейс `CarOutput` (добавить метод в интерфейс)+ - Считаем, что бак может принимать и бензин, и газ. Что именно туда заливается - определяется - горловиной, которая установлена на баке -- Топливная система должна устанавливаться "специалистом" - сборщиком нашей машины + горловиной, которая установлена на баке + +- Топливная система должна устанавливаться "специалистом" - сборщиком нашей машины+ Интерфейс бака и его связь с другими компонентами может выглядеть, например, вот так: ![LCE state diagram](http://www.plantuml.com/plantuml/proxy?src=https://raw.githubusercontent.com/Android-Developer-Basic/Kotlin-6/master/doc/Tank.puml) diff --git a/build.gradle b/build.gradle index dcb6872..b412722 100644 --- a/build.gradle +++ b/build.gradle @@ -1,15 +1,23 @@ plugins { - id 'org.jetbrains.kotlin.jvm' version '2.2.10' -} - -kotlin { - jvmToolchain(17) + id 'org.jetbrains.kotlin.jvm' version '2.0.21' } test { useJUnitPlatform() } +java { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} + +kotlin { + jvmToolchain(21) +} + group 'ru.otus' version '1.0-SNAPSHOT' @@ -18,6 +26,7 @@ repositories { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib" + + implementation("org.jetbrains.kotlin:kotlin-stdlib:2.0.21") implementation 'org.junit.jupiter:junit-jupiter:5.8.1' -} \ No newline at end of file +} diff --git a/src/main/kotlin/ru/otus/cars/Car.kt b/src/main/kotlin/ru/otus/cars/Car.kt index 559978c..68632eb 100644 --- a/src/main/kotlin/ru/otus/cars/Car.kt +++ b/src/main/kotlin/ru/otus/cars/Car.kt @@ -19,6 +19,11 @@ interface Car : CarInput { */ val carOutput: CarOutput + /** + * Топливная система авто + */ + val fuelSystem:FuelSystem + /** * Получить оборудование */ diff --git a/src/main/kotlin/ru/otus/cars/CarOutput.kt b/src/main/kotlin/ru/otus/cars/CarOutput.kt index 875339f..f4bbfbe 100644 --- a/src/main/kotlin/ru/otus/cars/CarOutput.kt +++ b/src/main/kotlin/ru/otus/cars/CarOutput.kt @@ -8,4 +8,5 @@ interface CarOutput { * Скажи текущую скорость */ fun getCurrentSpeed(): Int + fun getFuelLevel(): Int } \ No newline at end of file diff --git a/src/main/kotlin/ru/otus/cars/FuelSystem.kt b/src/main/kotlin/ru/otus/cars/FuelSystem.kt new file mode 100644 index 0000000..08cf5ea --- /dev/null +++ b/src/main/kotlin/ru/otus/cars/FuelSystem.kt @@ -0,0 +1,67 @@ +package ru.otus.cars + +import java.lang.RuntimeException + +/** + * Тип топлива: Бензин или Газ + */ +enum class Type{ + FUEL, GAS +} +interface Tank{ + var level: Int +} + +/** + * Горловина к топливному баку + */ +data class TankMouth(val type:Type, val tank:Tank, val car:Car){ + /** + * Заправка бака топливом через горловину + * @param level - сколько залить в бак + * @return сколько в баке после заправки + */ + fun addFuel(level: Int): Int { + if(car is Taz){ + throw RuntimeException("ТАЗ НЕ УМЕЕТ ЗАПРАВЛЯТЬСЯ") + } + this.tank.level += level + return this.tank.level + } +} + +class FuelSystem constructor(fuelType:Type, car:Car = Taz){ + private var tank:Tank + var tankMouth: TankMouth + + init { + when(fuelType){ + Type.FUEL -> { + this.tank = FuelTank() + } + Type.GAS -> { + this.tank = GasTank() + } + } + this.tankMouth = TankMouth(fuelType, this.tank, car) + } +} + +/** + * Реализация бака с бензином + * @version = 1.0 + */ +class FuelTank: Tank { + override var level = 0 + var type = "Бак с бензином" +} + +/** + * Реализация бака с газом + * @version = 1.0 + */ +class GasTank: Tank{ + override var level = 0 + var type = "Бак с газом" +} + diff --git a/src/main/kotlin/ru/otus/cars/Taz.kt b/src/main/kotlin/ru/otus/cars/Taz.kt index 49df937..84a7718 100644 --- a/src/main/kotlin/ru/otus/cars/Taz.kt +++ b/src/main/kotlin/ru/otus/cars/Taz.kt @@ -36,4 +36,6 @@ object Taz: Car { override fun wheelToLeft(degrees: Int) { throw NotImplementedError("Руля нет") } + + override val fuelSystem: FuelSystem = FuelSystem(Type.GAS) } \ No newline at end of file diff --git a/src/main/kotlin/ru/otus/cars/Vaz2107.kt b/src/main/kotlin/ru/otus/cars/Vaz2107.kt index be857d2..5078349 100644 --- a/src/main/kotlin/ru/otus/cars/Vaz2107.kt +++ b/src/main/kotlin/ru/otus/cars/Vaz2107.kt @@ -20,6 +20,7 @@ class Vaz2107 private constructor(color: String) : VazPlatform(color) { override fun build(plates: Car.Plates): Vaz2107 = Vaz2107("Зеленый").apply { this.engine = getRandomEngine() this.plates = plates + this.fuelSystem = FuelSystem(Type.GAS, this) } /** @@ -39,7 +40,6 @@ class Vaz2107 private constructor(color: String) : VazPlatform(color) { // Переопределяем свойство родителя override lateinit var engine: VazEngine private set - /** * Семерка едет так */ @@ -59,7 +59,8 @@ class Vaz2107 private constructor(color: String) : VazPlatform(color) { // Выводим состояние машины override fun toString(): String { - return "Vaz2107(plates=$plates, wheelAngle=$wheelAngle, currentSpeed=$currentSpeed)" + return "Vaz2107(plates=$plates, wheelAngle=$wheelAngle, currentSpeed=$currentSpeed, " + + "fuelType=${fuelSystem.tankMouth.type}, fuelLevel=${fuelSystem.tankMouth.tank.level})" } /** @@ -67,6 +68,9 @@ class Vaz2107 private constructor(color: String) : VazPlatform(color) { */ override val carOutput: CarOutput = VazOutput() + override lateinit var fuelSystem: FuelSystem + private set + /** * Имеет доступ к внутренним данным ЭТОГО ВАЗ-2107! */ @@ -74,5 +78,10 @@ class Vaz2107 private constructor(color: String) : VazPlatform(color) { override fun getCurrentSpeed(): Int { return this@Vaz2107.currentSpeed } + + override fun getFuelLevel(): Int { + return this@Vaz2107.fuelSystem.tankMouth.tank.level + } + } } \ No newline at end of file diff --git a/src/main/kotlin/ru/otus/cars/Vaz2108.kt b/src/main/kotlin/ru/otus/cars/Vaz2108.kt index 27b83b8..4b4cd26 100644 --- a/src/main/kotlin/ru/otus/cars/Vaz2108.kt +++ b/src/main/kotlin/ru/otus/cars/Vaz2108.kt @@ -21,6 +21,7 @@ class Vaz2108 private constructor(color: String) : VazPlatform(color) { override fun build(plates: Car.Plates): Vaz2108 = Vaz2108("Красный").apply { this.engine = getRandomEngine() this.plates = plates + this.fuelSystem = FuelSystem(Type.FUEL, this) } fun alignWheels(vaz2108: Vaz2108) { @@ -63,13 +64,16 @@ class Vaz2108 private constructor(color: String) : VazPlatform(color) { // Выводим состояние машины override fun toString(): String { - return "Vaz2108(plates=$plates, wheelAngle=$wheelAngle, currentSpeed=$currentSpeed)" + return "Vaz2108(plates=$plates, wheelAngle=$wheelAngle, currentSpeed=$currentSpeed, " + + "fuelType=${fuelSystem.tankMouth.type}, fuelLevel=\${fuelSystem.tankMouth.tank.level)" } /** * Делегируем приборы внутреннему классу */ override val carOutput: CarOutput = VazOutput() + override lateinit var fuelSystem: FuelSystem + private set /** * Имеет доступ к внутренним данным ЭТОГО ВАЗ-2108! @@ -78,5 +82,9 @@ class Vaz2108 private constructor(color: String) : VazPlatform(color) { override fun getCurrentSpeed(): Int { return this@Vaz2108.currentSpeed } + + override fun getFuelLevel(): Int { + return this@Vaz2108.fuelSystem.tankMouth.tank.level + } } } \ No newline at end of file diff --git a/src/main/kotlin/ru/otus/cars/main.kt b/src/main/kotlin/ru/otus/cars/main.kt index 978d0ef..17ef537 100644 --- a/src/main/kotlin/ru/otus/cars/main.kt +++ b/src/main/kotlin/ru/otus/cars/main.kt @@ -16,6 +16,21 @@ fun main() { techChecks() println("\n===> Taz...") println(Taz.color) + + val car2107:Car = Vaz2107.build(Car.Plates("а007аа", 152)) + println("До заправки: $car2107") + println("Заправляем на 10 литров") + car2107.fuelSystem.tankMouth.addFuel(10) + println("После заправки $car2107") + + val car2108:Car = Vaz2108.build(Car.Plates("а008аа", 152)) + println("До заправки: $car2108") + println("Заправляем на 15 литров") + car2108.fuelSystem.tankMouth.addFuel(15) + println("После заправки $car2108") + + Taz.fuelSystem.tankMouth.addFuel(5) + } fun driveCars() { @@ -54,7 +69,7 @@ fun garageMake() { fun getEquipment() { val cars = listOf( - Vaz2107.build(Car.Plates("123", 77)), + Vaz2107.build(Car.Plates("123", 77), ), Vaz2108.build(Car.Plates("321", 78)) ) From 9152ad4ae7e2f59e2bc63ecd5cd5898a71a50735 Mon Sep 17 00:00:00 2001 From: "Mikhail.Makhonin" Date: Mon, 8 Sep 2025 09:36:28 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20#2:=20=D0=97=D0=B0=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5?= =?UTF-8?q?=D0=BC=D1=81=D1=8F=20=D0=BD=D0=B0=20=D0=B7=D0=B0=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/otus/cars/FuelStation.kt | 42 +++++++++++++++++++++ src/main/kotlin/ru/otus/cars/FuelSystem.kt | 18 +++++---- src/main/kotlin/ru/otus/cars/Vaz2107.kt | 3 ++ src/main/kotlin/ru/otus/cars/Vaz2108.kt | 2 +- src/main/kotlin/ru/otus/cars/main.kt | 16 ++++++-- 5 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 src/main/kotlin/ru/otus/cars/FuelStation.kt diff --git a/src/main/kotlin/ru/otus/cars/FuelStation.kt b/src/main/kotlin/ru/otus/cars/FuelStation.kt new file mode 100644 index 0000000..de0948e --- /dev/null +++ b/src/main/kotlin/ru/otus/cars/FuelStation.kt @@ -0,0 +1,42 @@ +package ru.otus.cars + +import java.lang.Exception + +class FuelStation { + companion object { + + private lateinit var currentCar: Car + fun refuelCar(car: Car, litres: Int) { + println("Заправка авто: ${car.toString()} на ${litres.toString()} литров") + currentCar = car + + val isOk = when(car.fuelSystem.tankMouth.type){ + Type.GAS, Type.FUEL -> { + addFuel(litres) + true + } + else -> { + println("Не обслуживаентся") + false + } + } + if(isOk) + println("Заправлено. Уровень топлива в авто: ${car.carOutput.getFuelLevel()} литров") + else + println("Не заправлено. Уровень топлива в авто: ${car.carOutput.getFuelLevel()} литров") + + println("") + + } + + private fun addFuel(litres: Int): Boolean { + return try { + currentCar.fuelSystem.tankMouth.addFuel(litres) + } catch (e:Exception){ + false + } + } + + } + +} \ No newline at end of file diff --git a/src/main/kotlin/ru/otus/cars/FuelSystem.kt b/src/main/kotlin/ru/otus/cars/FuelSystem.kt index 08cf5ea..095dabd 100644 --- a/src/main/kotlin/ru/otus/cars/FuelSystem.kt +++ b/src/main/kotlin/ru/otus/cars/FuelSystem.kt @@ -21,20 +21,22 @@ data class TankMouth(val type:Type, val tank:Tank, val car:Car){ * @param level - сколько залить в бак * @return сколько в баке после заправки */ - fun addFuel(level: Int): Int { + fun addFuel(level: Int): Boolean { if(car is Taz){ throw RuntimeException("ТАЗ НЕ УМЕЕТ ЗАПРАВЛЯТЬСЯ") } + val fuelLevelBefore = this.tank.level this.tank.level += level - return this.tank.level + return (this.tank.level - fuelLevelBefore > 0) } } -class FuelSystem constructor(fuelType:Type, car:Car = Taz){ - private var tank:Tank - var tankMouth: TankMouth - - init { +class FuelSystem { + private val car:Car + private var tank:Tank // Топливный бак + var tankMouth: TankMouth // Горловина бака + constructor(fuelType:Type, car:Car = Taz){ + this.car = car when(fuelType){ Type.FUEL -> { this.tank = FuelTank() @@ -43,7 +45,7 @@ class FuelSystem constructor(fuelType:Type, car:Car = Taz){ this.tank = GasTank() } } - this.tankMouth = TankMouth(fuelType, this.tank, car) + this.tankMouth = TankMouth(fuelType, this.tank, this.car) } } diff --git a/src/main/kotlin/ru/otus/cars/Vaz2107.kt b/src/main/kotlin/ru/otus/cars/Vaz2107.kt index 5078349..d4490fc 100644 --- a/src/main/kotlin/ru/otus/cars/Vaz2107.kt +++ b/src/main/kotlin/ru/otus/cars/Vaz2107.kt @@ -68,6 +68,9 @@ class Vaz2107 private constructor(color: String) : VazPlatform(color) { */ override val carOutput: CarOutput = VazOutput() + /** + * Топливная система ВАЗ 2107 + */ override lateinit var fuelSystem: FuelSystem private set diff --git a/src/main/kotlin/ru/otus/cars/Vaz2108.kt b/src/main/kotlin/ru/otus/cars/Vaz2108.kt index 4b4cd26..b92f778 100644 --- a/src/main/kotlin/ru/otus/cars/Vaz2108.kt +++ b/src/main/kotlin/ru/otus/cars/Vaz2108.kt @@ -65,7 +65,7 @@ class Vaz2108 private constructor(color: String) : VazPlatform(color) { // Выводим состояние машины override fun toString(): String { return "Vaz2108(plates=$plates, wheelAngle=$wheelAngle, currentSpeed=$currentSpeed, " + - "fuelType=${fuelSystem.tankMouth.type}, fuelLevel=\${fuelSystem.tankMouth.tank.level)" + "fuelType=${fuelSystem.tankMouth.type}, fuelLevel=${fuelSystem.tankMouth.tank.level}" } /** diff --git a/src/main/kotlin/ru/otus/cars/main.kt b/src/main/kotlin/ru/otus/cars/main.kt index 17ef537..832a4bf 100644 --- a/src/main/kotlin/ru/otus/cars/main.kt +++ b/src/main/kotlin/ru/otus/cars/main.kt @@ -18,18 +18,26 @@ fun main() { println(Taz.color) val car2107:Car = Vaz2107.build(Car.Plates("а007аа", 152)) + val car2108:Car = Vaz2108.build(Car.Plates("а008аа", 152)) + + val cars:List = mutableListOf(car2107, car2108) + println("До заправки: $car2107") - println("Заправляем на 10 литров") + println("Заправляем \"Сами\" на 10 литров") car2107.fuelSystem.tankMouth.addFuel(10) println("После заправки $car2107") - val car2108:Car = Vaz2108.build(Car.Plates("а008аа", 152)) println("До заправки: $car2108") - println("Заправляем на 15 литров") + println("Заправляем \"Сами\" на 15 литров") car2108.fuelSystem.tankMouth.addFuel(15) println("После заправки $car2108") - Taz.fuelSystem.tankMouth.addFuel(5) + println("\nЗаправляемся на заправке:") + for(car in cars){ + FuelStation.refuelCar(car, 10) + } + + //Taz.fuelSystem.tankMouth.addFuel(5) } From 49e9cd70fd09b82f71c39cafc9a15361eb46cf5e Mon Sep 17 00:00:00 2001 From: "Mikhail.Makhonin" Date: Mon, 15 Sep 2025 15:06:18 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=20=D0=9C=D0=A0:=20=D0=BE?= =?UTF-8?q?=D1=81=D0=BB=D0=B0=D0=B1=D0=B8=D0=BB=20=D1=81=D0=B2=D1=8F=D0=B7?= =?UTF-8?q?=D1=8C=20=D0=BC=D0=B5=D0=B6=D0=B4=D1=83=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/otus/cars/FuelStation.kt | 13 ++++++------- src/main/kotlin/ru/otus/cars/FuelSystem.kt | 13 +++---------- src/main/kotlin/ru/otus/cars/Vaz2107.kt | 2 +- src/main/kotlin/ru/otus/cars/Vaz2108.kt | 2 +- src/main/kotlin/ru/otus/cars/main.kt | 8 +++++++- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/main/kotlin/ru/otus/cars/FuelStation.kt b/src/main/kotlin/ru/otus/cars/FuelStation.kt index de0948e..452590d 100644 --- a/src/main/kotlin/ru/otus/cars/FuelStation.kt +++ b/src/main/kotlin/ru/otus/cars/FuelStation.kt @@ -1,6 +1,6 @@ package ru.otus.cars -import java.lang.Exception +import java.lang.RuntimeException class FuelStation { companion object { @@ -9,13 +9,16 @@ class FuelStation { fun refuelCar(car: Car, litres: Int) { println("Заправка авто: ${car.toString()} на ${litres.toString()} литров") currentCar = car + if( currentCar is Taz){ + throw RuntimeException("ТАЗ НЕ УМЕЕТ ЗАПРАВЛЯТЬСЯ") + } val isOk = when(car.fuelSystem.tankMouth.type){ Type.GAS, Type.FUEL -> { addFuel(litres) true } - else -> { + else -> { println("Не обслуживаентся") false } @@ -30,11 +33,7 @@ class FuelStation { } private fun addFuel(litres: Int): Boolean { - return try { - currentCar.fuelSystem.tankMouth.addFuel(litres) - } catch (e:Exception){ - false - } + return currentCar.fuelSystem.tankMouth.addFuel(litres) } } diff --git a/src/main/kotlin/ru/otus/cars/FuelSystem.kt b/src/main/kotlin/ru/otus/cars/FuelSystem.kt index 095dabd..85d0b2d 100644 --- a/src/main/kotlin/ru/otus/cars/FuelSystem.kt +++ b/src/main/kotlin/ru/otus/cars/FuelSystem.kt @@ -1,7 +1,5 @@ package ru.otus.cars -import java.lang.RuntimeException - /** * Тип топлива: Бензин или Газ */ @@ -15,16 +13,13 @@ interface Tank{ /** * Горловина к топливному баку */ -data class TankMouth(val type:Type, val tank:Tank, val car:Car){ +data class TankMouth(val type:Type, val tank:Tank){ /** * Заправка бака топливом через горловину * @param level - сколько залить в бак * @return сколько в баке после заправки */ fun addFuel(level: Int): Boolean { - if(car is Taz){ - throw RuntimeException("ТАЗ НЕ УМЕЕТ ЗАПРАВЛЯТЬСЯ") - } val fuelLevelBefore = this.tank.level this.tank.level += level return (this.tank.level - fuelLevelBefore > 0) @@ -32,11 +27,9 @@ data class TankMouth(val type:Type, val tank:Tank, val car:Car){ } class FuelSystem { - private val car:Car private var tank:Tank // Топливный бак var tankMouth: TankMouth // Горловина бака - constructor(fuelType:Type, car:Car = Taz){ - this.car = car + constructor(fuelType:Type){ when(fuelType){ Type.FUEL -> { this.tank = FuelTank() @@ -45,7 +38,7 @@ class FuelSystem { this.tank = GasTank() } } - this.tankMouth = TankMouth(fuelType, this.tank, this.car) + this.tankMouth = TankMouth(fuelType, this.tank) } } diff --git a/src/main/kotlin/ru/otus/cars/Vaz2107.kt b/src/main/kotlin/ru/otus/cars/Vaz2107.kt index d4490fc..fb85c24 100644 --- a/src/main/kotlin/ru/otus/cars/Vaz2107.kt +++ b/src/main/kotlin/ru/otus/cars/Vaz2107.kt @@ -20,7 +20,7 @@ class Vaz2107 private constructor(color: String) : VazPlatform(color) { override fun build(plates: Car.Plates): Vaz2107 = Vaz2107("Зеленый").apply { this.engine = getRandomEngine() this.plates = plates - this.fuelSystem = FuelSystem(Type.GAS, this) + this.fuelSystem = FuelSystem(Type.GAS) } /** diff --git a/src/main/kotlin/ru/otus/cars/Vaz2108.kt b/src/main/kotlin/ru/otus/cars/Vaz2108.kt index b92f778..546b649 100644 --- a/src/main/kotlin/ru/otus/cars/Vaz2108.kt +++ b/src/main/kotlin/ru/otus/cars/Vaz2108.kt @@ -21,7 +21,7 @@ class Vaz2108 private constructor(color: String) : VazPlatform(color) { override fun build(plates: Car.Plates): Vaz2108 = Vaz2108("Красный").apply { this.engine = getRandomEngine() this.plates = plates - this.fuelSystem = FuelSystem(Type.FUEL, this) + this.fuelSystem = FuelSystem(Type.FUEL) } fun alignWheels(vaz2108: Vaz2108) { diff --git a/src/main/kotlin/ru/otus/cars/main.kt b/src/main/kotlin/ru/otus/cars/main.kt index 832a4bf..959998d 100644 --- a/src/main/kotlin/ru/otus/cars/main.kt +++ b/src/main/kotlin/ru/otus/cars/main.kt @@ -1,5 +1,7 @@ package ru.otus.cars +import java.lang.Exception + fun main() { println("\n===> drive cars...") driveCars() @@ -34,7 +36,11 @@ fun main() { println("\nЗаправляемся на заправке:") for(car in cars){ - FuelStation.refuelCar(car, 10) + try { + FuelStation.refuelCar(car, 10) + }catch (e:Exception){ + println("${car.toString()} не заправлена" ) + } } //Taz.fuelSystem.tankMouth.addFuel(5)