Skip to content

Instantly share code, notes, and snippets.

@sherifflight
Created July 24, 2019 22:03
Show Gist options
  • Save sherifflight/11d9475219915ea5f936a928fc6a9b7e to your computer and use it in GitHub Desktop.
Save sherifflight/11d9475219915ea5f936a928fc6a9b7e to your computer and use it in GitHub Desktop.
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