-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lesson5 #6
base: master
Are you sure you want to change the base?
Lesson5 #6
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// | ||
// main.swift | ||
// lesson5 | ||
// | ||
// Created by Vladislav Elkin on 31.07.2020. | ||
// Copyright © 2020 Vladislav Elkin. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
enum DoorState{ | ||
case open, close; | ||
} | ||
|
||
enum EngineState{ | ||
case start, stop; | ||
} | ||
|
||
enum VolumeState{ | ||
case full, empty; | ||
} | ||
|
||
enum VolumeAction { | ||
case add, get; | ||
} | ||
|
||
protocol AbstractCar { | ||
var brand: String {get set} | ||
var year: Int {get set} | ||
var trunkVolume: Double {get set} | ||
var engineState: EngineState {get set} | ||
var doorState: DoorState {get set} | ||
var volumeState: VolumeState {get set} | ||
|
||
} | ||
|
||
extension AbstractCar { | ||
mutating func changeDoorState (state: DoorState){ | ||
self.doorState = state; | ||
} | ||
|
||
mutating func changeEngineState(state: EngineState){ | ||
self.engineState = state; | ||
} | ||
|
||
mutating func changeVolume(action: VolumeAction, count: Double) | ||
{ | ||
switch action { | ||
|
||
case .add where volumeState == .full: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. молодец избавился от вложенности |
||
print("Trunk is full"); | ||
case.add where count >= trunkVolume: | ||
volumeState = .full; | ||
print("All added, Trunk is full"); | ||
case .add: | ||
print("Added: \(count)"); | ||
|
||
|
||
Comment on lines
+58
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. зачем тут пустые строки? |
||
case .get where volumeState == .empty: | ||
print("Trunk is empty"); | ||
case .get where count >= trunkVolume: | ||
volumeState = .empty; | ||
print("Trunk is empty"); | ||
case .get: | ||
print("Get: \(count)"); | ||
|
||
} | ||
} | ||
} | ||
|
||
|
||
class TrunkCar: AbstractCar { | ||
var brand: String | ||
var year: Int | ||
var trunkVolume: Double | ||
var engineState: EngineState | ||
var doorState: DoorState | ||
var volumeState: VolumeState | ||
var destination: String | ||
|
||
init(brand: String, year: Int, trunkVolume: Double, engineState: EngineState, doorState: DoorState, volumeState: VolumeState, destination: String) { | ||
self.brand = brand; | ||
self.year = year; | ||
self.trunkVolume = trunkVolume; | ||
self.engineState = engineState; | ||
self.doorState = doorState; | ||
self.volumeState = volumeState; | ||
self.destination = destination; | ||
} | ||
|
||
} | ||
|
||
extension TrunkCar: CustomStringConvertible{ | ||
var description: String { | ||
return "Brand: \(brand) Year: \(year) TrunkVolume: \(trunkVolume) EngineState: \(engineState) DoorState: \(doorState) VolumeState: \(volumeState) Destination: \(destination)"; | ||
} | ||
|
||
|
||
} | ||
|
||
class SportCar: AbstractCar { | ||
var brand: String | ||
var year: Int | ||
var trunkVolume: Double | ||
var engineState: EngineState | ||
var doorState: DoorState | ||
var volumeState: VolumeState | ||
var maxSpeed: Int | ||
var power: Int | ||
|
||
init(brand: String, year: Int, trunkVolume: Double, engineState: EngineState, doorState: DoorState, volumeState: VolumeState, maxSpeed: Int, power: Int) { | ||
self.brand = brand; | ||
self.year = year; | ||
self.trunkVolume = trunkVolume; | ||
self.engineState = engineState; | ||
self.doorState = doorState; | ||
self.volumeState = volumeState; | ||
self.maxSpeed = maxSpeed; | ||
self.power = power; | ||
Comment on lines
+113
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. избавляйся от привычки точек с запятыми |
||
} | ||
|
||
} | ||
|
||
extension SportCar: CustomStringConvertible{ | ||
var description: String { | ||
return "Brand: \(brand) Year: \(year) TrunkVolume: \(trunkVolume) EngineState: \(engineState) DoorState: \(doorState) VolumeState: \(volumeState) MaxSpeed: \(maxSpeed) Power: \(power)"; | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
var mers = SportCar(brand: "mersede", year: 2019, trunkVolume: 200, engineState: .stop, doorState: .close, volumeState: .full, maxSpeed: 320, power: 612); | ||
|
||
mers.changeDoorState(state: .open); | ||
mers.changeEngineState(state: .start); | ||
|
||
print(mers); | ||
|
||
var scania = TrunkCar(brand: "Scania", year: 2011, trunkVolume: 1000, engineState: .start, doorState: .open, volumeState: .empty, destination: "Moscow") | ||
|
||
scania.changeDoorState(state: .close); | ||
|
||
print(scania); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не нужно добавлять
Abstract