Created
July 24, 2019 22:03
-
-
Save sherifflight/11d9475219915ea5f936a928fc6a9b7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car { | |
let model: String | |
let color: String | |
init(model: String, color: String) { | |
self.model = model | |
self.color = color | |
} | |
func distance(_ speed: Int, _ time: Int) -> Int { | |
return speed * time | |
} | |
func execute(_ go: Go) { | |
let dis = distance(go.speed, go.time) | |
switch go.direction { | |
case Direction.up: | |
print("\(self.model) Car поехала прямо и прошла \(dis)") | |
case Direction.down: | |
print("\(self.model) Car поехала назад и прошла \(dis)") | |
case Direction.right: | |
print("\(self.model) Car поехала направо и прошла \(dis)") | |
case Direction.left: | |
print("\(self.model) Car поехала налево и прошла \(dis)") | |
} | |
} | |
} | |
enum Direction: String { | |
case up = "up" | |
case down = "down" | |
case right = "right" | |
case left = "left" | |
} | |
struct Go { | |
let direction: Direction | |
let speed: Int | |
let time: Int | |
} | |
let car = Car(model: "Some Model", color: "some color") | |
let direction = Go(direction: Direction.up, speed: 10, time: 2) | |
car.execute(direction) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment