Branches-Steph_Garcia#47
Conversation
Solar SystemWhat We're Looking For
Hi Steph! Good work on this project. Your code here to practice object-oriented program is exactly what we were looking for-- great job on making There happen to be a few bugs that occur with the Besides the user flow breaking, I feel really confident about the object-oriented code here. I think that if you had more time to work out the bugs in the That being said, good work; let me know if you have questions! |
| @fun_fact = fun_fact | ||
|
|
||
| if @mass_kg <= 0 | ||
| raise ArgumentError.new "Invalid input must be greater than 0" |
There was a problem hiding this comment.
When I put in a user input of 0 or 9banana for the mass, my program raises an error here and breaks! This is good for programmers, but in terms of being a user, this is really weird to look at.
As a user, I probably would prefer if the main method told me to re-input my mass in kg if I put in bad input.
That being said, I think your Planet class code looks correct, and it should stay the same :) This way, the error will only be raised if we do something weird, like if we made unit tests that did the wrong thing.
| def find_planet_by_name(input_planet) | ||
| @planets.each do |each_planet| | ||
| if input_planet.downcase == each_planet.planet_name | ||
| return each_planet |
There was a problem hiding this comment.
What happens if the input_planet name is never found in the array of @planets? If input_planet is found (like earth), then this each loop will eventually run return each_planet. However, what happens if line 25 is never true?
What happens is a very weird Ruby thing: Ruby will implicitly return the array @planets.
You have three options here to "fix" this: You can either change this find_planet_by_name method to return something special if the planet is never found, OR you change main so that if sun.find_planet_by_name doesn't get a Planet instance back, then it does something special... OR you can do both. (It's likely you'd have to do both)
| puts "Here are the planets in your SolarSystem:" | ||
| puts sun.list_planets | ||
| puts "Would you like more information about one of to the planets?" | ||
| user_response = gets.chomp |
There was a problem hiding this comment.
Hm, I don't think this re-assignment of user_response gets used ...
| puts "Which one would you like more information about?" | ||
| user_choice_planet = gets.chomp.to_s.downcase | ||
| found_planet = sun.find_planet_by_name(user_choice_planet) | ||
| puts found_planet.summary |
There was a problem hiding this comment.
If the program asks me "Which one would you like more information about?" and I respond 9banana, I get an error here: undefined method 'summary' for #<Array:0x00007fb5e0077a40> (NoMethodError). This is because here we are calling found_planet.summary, meaning found_planet was an Array in this case. This line works when found_planet is an instance of Planet. To find out why found_planet was an array (instead of an instance of Planet), I would look at the line above, found_planet = sun.find_planet_by_name(user_choice_planet)... I'm leaving a comment on SolarSystem's find_planet_by_name
|
|
||
| #Where I allow user to add another planet: | ||
| puts "Would you like to add you own planet to the sun Solarsystem?" | ||
| user_response = gets.chomp.to_s.downcase |
There was a problem hiding this comment.
Your code is set up for main to run over and over again as long as the user says yes to some prompt that would ask if the user wants to re-run the Solar System program (I know this from your while user_response == 'yes' line!).
However, because you re-assign user_response here (and above), your while loop won't loop because user_response may change here.
This is a shame because then your program overall exits after you add a planet!
Solar System
Congratulations! You're submitting your assignment.
Comprehension Questions
initializemethod run? What does it do?Hashinstead of an instance of a class?SolarSystemclass used aHashinstead of anArrayto store the list of planets?requirestatements? Which files neededrequires, and which did not? What is the pattern?