Ampers: Abinnet Ainalem (Basic requirements met)#38
Ampers: Abinnet Ainalem (Basic requirements met)#38Abiaina wants to merge 2 commits intoAda-C9:masterfrom
Conversation
| puts "Enter anything else to take a break from learning.\n" | ||
| play = gets.chomp.downcase | ||
| end | ||
| puts "\n Live long and prosper" |
| } ] | ||
|
|
||
| # UI: welcomes and prompts user for input | ||
| puts "Hello and welcome to Planet Gazer" |
There was a problem hiding this comment.
Why is this indented?!!
In the future before submitting use Atom's autoindent feature!
| puts "\nType the planet name exactly as it appears below to learn more." | ||
| puts "Or, enter NEW to create your own planet\n" | ||
|
|
||
| solar_system = SolarSystem.new(planets) |
There was a problem hiding this comment.
A couple of things here:
- You're initializing
solar_systemwith an array of hashes and NOT an array ofPlanetinstances! - You're re-creating the
SolarSysteminstance each time the loop repeats. That's a bit inefficient. Only put code in a loop that needs to be there.
| current_planets = solar_system.cycle_through_system | ||
| puts "\n" | ||
| current_planets.each {|planet| puts planet.upcase} | ||
| user_planet_choice = gets.chomp.downcase |
There was a problem hiding this comment.
Why show the planet names in all caps and then downcase the user entry?
| # Stores an array of hashes of info on planets | ||
| def initialize (planets) | ||
| @planets = planets | ||
| @ranked_planets = [] |
There was a problem hiding this comment.
Do you need 2 instance variables? This looks like it should be a local variable holding an array of planet names (and numbers).
| @color = planet_info[:color] | ||
| end | ||
| def user_friendly_display | ||
| return "\nAt #@sun_distance million miles from the sun,\nA year on the #@color planet #@name passes in #@year_length days.\n" |
|
|
||
| # Cycles through list of planets | ||
| # Returns numbered list of planets, w/ respect to sun proximity | ||
| def cycle_through_system |
There was a problem hiding this comment.
This method should just return a list of planet names, not add elements to another instance variable. If you hadn't recreated the SolarSystem each iteration of the main loop you would end up with double and triple entries for each planet in @ ranked_planets.
Solar SystemWhat We're Looking For
|
Solar System
Congratulations! You're submitting your assignment.
Comprehension Questions
initializemethod in your class?SolarSystemused anArrayvs aHash.