Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

airport_challenge #2511

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

airport_challenge #2511

wants to merge 14 commits into from

Conversation

SamButton12
Copy link

@SamButton12 SamButton12 commented Apr 25, 2022

Sam Button

User stories

Please list which user stories you've implemented (delete the ones that don't apply).

  • User story 1: "I want to instruct a plane to land at an airport"
  • User story 2: "I want to instruct a plane to take off from an airport and confirm that it is no longer in the airport"
  • User story 3: "I want to prevent landing when the airport is full"
  • User story 5: "I want to prevent takeoff when weather is stormy"
  • User story 6: "I want to prevent landing when weather is stormy"

README checklist

Does your README contains instructions for

  • how to install,
  • how to run,
  • and how to test your code?

Here is a pill that can help you write a great README!


def capacity_full?
max_capacity = 10
@planes.size >= max_capacity

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't say without running it, but should this be @planes.size > max_capacity? I think this would make max_capacity 9

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, you should use the capacity you passed in in the initialize method, stored in @capacity. Otherwise, it's a duplication of code, and max_capacity will remain static at 10 regardless of the user input.

@planes = []
end

def land(plane)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, simple names. I feel like I overcomplicated mine with land_plane and release_plane.

Copy link

@S-Spiegl S-Spiegl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment

Copy link

@eoinmakers eoinmakers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress with this, but there are some pockets of logic that are incomplete. Check out the snippets and suggestions I shared, and let me know if you'd like to take a look together!

@@ -0,0 +1,23 @@
class Airport
attr_reader :plane

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to expose the plane variable outside of this class?

attr_reader :plane

def initialize(capacity)
@capacity = capacity

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you implement a default capacity, in case the user didn't specify one? Maybe take a look at including a default argument: https://www.rubyguides.com/2018/06/rubys-method-arguments/

end

def takeoff(plane)
raise 'cannot take off, weather is stormy' if stormy?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can having a plane take off be reflected?

You're currently storing landed planes in @planes - they need to be decremented from this array once they take off, to show they're no longer in the airport.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order for Weather's stormy? method to be called here, you could refactor your class with the following snippets (as an example):

def initialize(capacity, weather)
     @capacity = capacity
     @weather = weather
def

With the above, you would initialize a Weather instance with Weather.new, and pass that in as an argument when initialising Airport.new.

Then in your land/take_off methods, you could write:

raise 'cannot take off, weather is stormy' if @weather.stormy?

The last remaining step will be to refactor your Weather class itself - currently, the result will always be the same. Can you think of a way you might randomise the result, so that it's sometimes sunny and sometimes stormy?


def capacity_full?
max_capacity = 10
@planes.size >= max_capacity

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, you should use the capacity you passed in in the initialize method, stored in @capacity. Otherwise, it's a duplication of code, and max_capacity will remain static at 10 regardless of the user input.

class Plane
def at_airport?
false
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused methods should be removed before opening a PR.

# airport = Airport.new
# expect(airport).to respond_to :land
# end
# not needed as it is fully covered by a future test

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove unneeded tests / commented out code / tests too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants