GithubHelp home page GithubHelp logo

airport-challenge's Introduction

Airport Challenge

Build Status Coverage Status Code Climate

We have a request from a client to write the software to control the flow of planes at an airport. The planes can land and take off provided that the weather is sunny. Occasionally it may be stormy, in which case no planes can land or take off. Here are the user stories that we worked out in collaboration with the client:

User Stories

As an air traffic controller
So planes can land safely at my airport
I would like to instruct a plane to land

As an air traffic controller
So planes can take off safely from my airport
I would like to instruct a plane to take off

As an air traffic controller
So that I can avoid collisions
I want to prevent airplanes landing when my airport if full

As an air traffic controller
So that I can avoid accidents
I want to prevent airplanes landing or taking off when the weather is stormy

As an air traffic controller
So that I can ensure safe take off procedures
I want planes only to take off from the airport they are at

As the system designer
So that the software can be used for many different airports
I would like a default airport capacity that can be overridden as appropriate

As an air traffic controller
So the system is consistent and correctly reports plane status and location
I want to ensure a flying plane cannot take off and cannot be in an airport

As an air traffic controller
So the system is consistent and correctly reports plane status and location
I want to ensure a plane that is not flying cannot land and must be in an airport

As an air traffic controller
So the system is consistent and correctly reports plane status and location
I want to ensure a plane that has taken off from an airport is no longer in that airport

Here are the user stories converted into a Domain Model:

Object Messages Object Messages Object Messages
airport land plane land weather stormy?
take_off take_off
airport

Approach

My approach to solving this challenge was to start with an Airport class, build it as much as I could until I needed to start understanding how one class object would interact with another one. At some point I found it's better to extract the weather behaviour into a separate class, with this class containing a single method #stormy? which returned true with a probability of 5%. It has been implemented with the Kernel method rand.

Installation

Clone the repository:

$ git clone [email protected]:yevdyko/airport-challenge.git

Change into the directory:

$ cd airport-challenge

If you don't have bundle already, run the command:

$ gem install bundle

Install all dependencies with:

$ bundle

Testing

To run the tests:

$ rspec

How to use

To see the code in action, open IRB and require the files:

2.3.0 :001 > require './lib/weather'
 => true
2.3.0 :002 > require './lib/plane'
 => true
2.3.0 :003 > require './lib/airport'
 => true

Create a weather object:

2.3.0 :004 > weather = Weather.new
 => #<Weather:0x007f94420bb430>

Create a new airport:

2.3.0 :005 > airport = Airport.new(weather)
 => #<Airport:0x007f94420b22b8 @weather=#<Weather:0x007f94420bb430>,
 @capacity=25, @planes=[]>

Create some planes:

2.3.0 :006 > plane1 = Plane.new
 => #<Plane:0x007f94420aa1d0 @flying=true>
2.3.0 :007 > plane2 = Plane.new
 => #<Plane:0x007f94420a02c0 @flying=true>

Land planes:

2.3.0 :008 > airport.land(plane1)
 => [#<Plane:0x007f94420aa1d0 @flying=false, @airport=#<Airport:0x007f94420b22b8
 @weather=#<Weather:0x007f94420bb430>, @capacity=25, @planes=[...]>>]
2.3.0 :009 > airport.land(plane2)
 => [#<Plane:0x007f94420aa1d0 @flying=false, @airport=#<Airport:0x007f94420b22b8
 @weather=#<Weather:0x007f94420bb430>, @capacity=25, @planes=[...]>>,
 #<Plane:0x007f94420a02c0 @flying=false, @airport=#<Airport:0x007f94420b22b8
 @weather=#<Weather:0x007f94420bb430>, @capacity=25, @planes=[...]>>]

If the weather is stormy, you may need to try landing the plane a few times.

Send a plane to take off:

2.3.0 :010 > airport.take_off(plane2)
 => #<Plane:0x007f94420a02c0 @flying=false, @airport=#<Airport:0x007f94420b22b8
 @weather=#<Weather:0x007f94420bb430>, @capacity=25,
 @planes=[#<Plane:0x007f94420aa1d0 @flying=false, @airport=#<Airport:0x007f94420b22b8 ...>>,
 #<Plane:0x007f9442098890 @flying=false, @airport=#<Airport:0x007f94420b22b8 ...>>]>>

Check the planes in the airport:

2.3.0 :011 > airport.planes
 => [#<Plane:0x007f94420aa1d0 @flying=false, @airport=#<Airport:0x007f94420b22b8
 @weather=#<Weather:0x007f94420bb430>, @capacity=25, @planes=[...]>>]

airport-challenge's People

Contributors

bebbs avatar dbugsy avatar leoallen85 avatar mihailiviucojocar avatar nikeshashar avatar silvabox avatar spike01 avatar tansaku avatar

Watchers

 avatar  avatar

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.