Skip to content

Conversation

@bennettrahn
Copy link

Solar System

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
What was the purpose of the initialize method in your class? to define all the instance variables and take input for those variables from the creation of a new class.
Describe an instance variable you used and what you used it for. @distance_from_sun gave the distance from the sun in AU so that you could find the distance between planets by using simple subtraction.
Describe what the difference would be if your SolarSystem used an Array vs a Hash. My solar system didn't use a hash? In wave one I had one and it was nice to call the keys, but once I switched to methods that was easier. Arrays are hard because you have to know the index of some thing so its not intuitive.
Do you feel like you used consistent indentation throughout your code? yes? cmd-I works wonders.

@bennettrahn bennettrahn changed the title Create solar_system_wave3.rb Pipes - Bennett - Solar System Aug 16, 2017
@droberts-sea
Copy link

Solar System

What We're Looking For

Feature Feedback
Created Custom Class with initialize method & instance variables. Yes
Used an Array to store a list of planets in the SolarSystem class. Yes
Readable code with consistent indentation. Yes
Created a pull request with your name & the template questions answered. Yes

Great work overall! I've commented on a bunch of little things below, but in general I'm quite happy with the code you've submitted.

# method to access the planet class by name so as to use planet methods on it
def planets_by_name(name)
planet_names = []
@planets.each do |planet_class|

Choose a reason for hiding this comment

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

I really like the idea of making this its own method. Very concise bit of functionality.

You're implementation is a little odd to me though - do you really need to pull out the planet names? Why not:

@planets.each do |planet|
  if planet.name == name
    return planet
  end
  return nil
end

all_planets(:name).length.times do |i|
planet_list += "#{i + 1}. #{all_planets(:name)[i]}"
if type == :line
planet_list += "\n"

Choose a reason for hiding this comment

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

This is a clever way to make your functionality more flexible. Here is a question: Why not pass in the whitespace you want as type, instead of a symbol representing it?

# method to create a table with info from each planet called by the array passed to table_create
def table_create(table_arr)

planet_table_headings = ["Name", "|Mass", "|Index from Sun", "|Circumference", "|Color", "|Year Length", "|Distance from the Sun"]

Choose a reason for hiding this comment

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

I like this table.



mercury_class = Planet.new("Mercury", 3.285e+23, 1, 9525, "Orange", 0.24, 0.39)
venus_class = Planet.new("Venus", 4.87e+24, 2, 23628, "Yellow", 0.62, 0.72)

Choose a reason for hiding this comment

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

You use the term class often in variable names. I would recommend avoiding this - in general, it's usually clear when you've got an instance of a class. Instead, calling these mercury or venus might be more readable.

mars_class = Planet.new("Mars", 6.39e+23, 4, 13263, "Red", 1.88, 1.52)
jupiter_class = Planet.new("Jupiter", 1.898e+27, 5, 272946, "Striped", 11.78, 5.2)

our_solar_system = SolarSystem.new("Milky Way", 1.32e+10, [mercury_class, venus_class, earth_class, mars_class, jupiter_class])

Choose a reason for hiding this comment

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

Since you're creating all these local variables just to add them to an array, a more concise way to do this might be:

planet_array = [
  Planet.new("Mercury", 3.285e+23, 1, 9525, "Orange", 0.24, 0.39),
  Planet.new("Venus", 4.87e+24, 2, 23628, "Yellow", 0.62, 0.72),
  # ...
]
our_solar_system = SolarSystem.new("Milky Way", 1.32e+10, planet_array)

This makes it clear to the reader that we won't be using the planets individually, only through the collection, and also saves you having to come up with a bunch of variable names.

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.

2 participants