Giter VIP home page Giter VIP logo

hw-w07d05-ruby-oop's Introduction

Ruby Objects Homework

Objectives:

  • Apply your knowledge of Ruby to solve a real world problem.
  • Get really good at Ruby classes and objects

Activity

Create a program that models a subway system.

The program takes the line and stop that a user is getting on at and the line and stop that user is getting off at and prints the journey and the total number of stops for the trip in the console:

There are 3 subway lines:

Red line

  • South Station
  • Park Street
  • Kendall
  • Central
  • Harvard
  • Porter
  • Davis
  • Alewife

Green line

  • Government Center
  • Park Street
  • Boylston
  • Arlington
  • Copley
  • Hynes
  • Kenmore

Orange line

  • North Station
  • Haymarket
  • Park Street
  • State
  • Downtown Crossing
  • Chinatown
  • Back Bay
  • Forest Hills

All 3 subway lines intersect at Park Street, but there are no other intersection points.

Goal

Tell the user the number of stops between stations using ruby classes.

class Subway
  def stops_between_stations(start_line, start_station, end_line, end_station)
  end
end
  
# One line, all the stations on that line
class Line
end

# One station
class Station
end

And we should be able to find the number of stops with

mbta = Subway.new
mbta.stops_between_stations('Red', 'Alewife', 'Red', 'Alewife') # 0
mbta.stops_between_stations('Red', 'Alewife', 'Red', 'South Station') # 7
mbta.stops_between_stations('Red', 'South Station', 'Green', 'Kenmore') # 6

Bonus

Tell the user the number of stops between stations AND the stops IN ORDER that they will pass through or change at.

mbta = Subway.new
mbta.stops_between_stations('Red', 'South Station', 'Green', 'Kenmore') 
# "You must travel through the following stops on the Red line:"
# "South Station and Park Street"
# "Change at Park Street."
# "Your trip continues through the following stops on Green Line:" 
# "Boylston, Arlington, Copley, Hines, and Kenmore."
# "7 stops in total."

Double Bonus

Use get to allow the user to input their start line, start station, end line, and end station.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.