Last active
January 9, 2020 20:19
-
-
Save Naomi-Dennis/057e40ea1780e22d7d2afcdf37524673 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 SubwayTrain | |
attr_accessor :averageSpeed, :subwayCar, :speed, :subwayCars | |
def initialize | |
self.averageSpeed = 17 | |
self.speed = 0; | |
self.subwayCars = []; | |
end | |
def allowPassengersOnBoard | |
puts "Train arriving at station." | |
slowDownToHalt | |
puts "Train Stopped." | |
openDoors | |
puts "Doors Open." | |
sleep 1 | |
puts "Stand Clear of the Closing Doors" | |
increaseSpeedToAverageSpeed | |
puts "Train leaving station." | |
end | |
def slowDownToHalt | |
while(speed > 0) | |
self.speed -= 1 | |
end | |
end | |
def openDoors | |
subwayCars.each do | subwayCar | | |
subwayCar.close() | |
end | |
end | |
def increaseSpeedToAverageSpeed | |
while(speed < averageSpeed) | |
self.speed += 1 | |
end | |
end | |
end | |
train = SubwayTrain.new | |
train.speed = 100; | |
train.allowPassengersOnBoard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment