Conversation
Solar SystemWhat We're Looking For
|
| if answer1 == "y" | ||
| print "Please enter the planet name" | ||
| new_planet = gets.chomp | ||
| print "Enter the desc" |
There was a problem hiding this comment.
You should give some space between the prompt and the input.
like: print "Enter the description ==> "
Same for all of the following.
| #Start of user interface | ||
| print"Welcome to the Solar System\n" | ||
| answer = "y" | ||
| while answer.include?("y") |
There was a problem hiding this comment.
The main loop never lets you add a Planet until it's done. Then you can't view the Planet you added.
|
|
||
| #Create Solar System Class | ||
| class SolarSystem | ||
| attr_accessor :planet |
There was a problem hiding this comment.
Why make planet an accessor? Why not a reader? Do you have a reason users would be able to change planet?
| def check | ||
| choice=gets.chomp.to_i | ||
| if choice == 1 | ||
| element = Planet.new("Mercury","Smallest planet","47.8km/sec","4878km","87.97days","70millionkm") |
There was a problem hiding this comment.
Why create new planets here? Why not simply return the Planet from @planet?
Look at this method closely? Think about how you could create a method that takes a number and returns the indicated planet from @planet. Get help from me or a tutor/TA if you need.
| class SolarSystem | ||
| attr_accessor :planet | ||
| def initialize(planet) | ||
| @planet = planet |
There was a problem hiding this comment.
Since @planet is going to hold a list of planets, it should probably be plural (@planets as opposed to @planet).
| end | ||
| end | ||
| #Method to add new planet from user input | ||
| def create_planet_userinput(new_planet,new_planet_desc,new_planet_orbit,new_planet_diameter, |
There was a problem hiding this comment.
You have this and following code indented, it shouldn't be.
Solar System
Congratulations! You're submitting your assignment.
Comprehension Questions
initializemethod in your class?SolarSystemused anArrayvs aHash.