Last active
August 23, 2016 16:27
-
-
Save livmaria7891/d15f7a3d14a27cab598de2443bb9541f to your computer and use it in GitHub Desktop.
Solar System Wave 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Planet | |
def initialize(name,moons,escape_v,temp,type,distance) | |
@name = name | |
@moons = moons | |
@escape_v = escape_v | |
@surface_temp = temp | |
@type = type | |
@distance_from_the_sun = distance | |
end | |
attr_reader :name | |
def to_s | |
puts "#{@name} is a #{@type} planet!\n\nNumber of moons: #{@moons}\nAverage Surface Temperature: #{@surface_temp}\nDistance from the Sun: #{@distance_from_the_sun}\nEscape Velocity: #{@escape_v}\n\n\n" | |
end | |
end | |
# class SolarSystem | |
# | |
# def initialize(planets) | |
# @planets = [planets] | |
# @planets.flatten! | |
# end | |
# | |
# def planets | |
# @planets | |
# end | |
# | |
# def add_planets(new_planets) | |
# @planets.push(new_planets).flatten! | |
# print @planets | |
# end | |
# end | |
mercury = Planet.new("Mercury",0,4300,452,:rocky,57909175) | |
venus = Planet.new("Venus",0,10400,726,:rocky,108208930) | |
earth = Planet.new("Earth",1,11200,281,:rocky,149597890) | |
mars = Planet.new("Mars",2,5000,218,:rocky,227936640) | |
jupiter = Planet.new("Jupiter",67,59500,120,:gaseous,778412020) | |
saturn = Planet.new("Saturn",62,35600,88,:gaseous,886715600) | |
uranus = Planet.new("Uranus",27,21300,59,:gaseous,2870972200) | |
neptune = Planet.new("Neptune",14,23300,48,:gaseous,4498252900) | |
#Optional Enhancement for USER INPUT | |
puts "Here are the planets:\n1. #{mercury.name}\n2. #{venus.name}\n3. #{earth.name}\n4. #{mars.name}\n5. #{jupiter.name}\n6. #{saturn.name}\n7. #{uranus.name}\n8. #{neptune.name}\n" | |
go = true | |
while go | |
print "Type a planet's name to learn more about it, or type 'exit' when you're finished: " | |
choice = gets.chomp.upcase | |
case choice | |
when "MERCURY" | |
puts mercury | |
when "VENUS" | |
puts venus | |
when "EARTH" | |
puts earth | |
when "MARS" | |
puts mars | |
when "JUPITER" | |
puts jupiter | |
when "SATURN" | |
puts saturn | |
when "URANUS" | |
puts uranus | |
when "NEPTUNE" | |
puts neptune | |
when "EXIT" | |
go = false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For Wave 1, overall I feel like I accomplished the learning goals. I understand how to and can successfully create a class and use an initialize method. I can also create and use instance variables, however I’m not completely clear on when I do and don’t need to use an instance variable versus a ‘regular’ variable. I tend to make every variable in a class an instance variable, even though I don’t think it’s always necessary. I also see in my code that I used an attr_reader method, but only for the name variable. As look at it now, I’m not sure why I did that or what purpose it serves. If I did this project again, I would see if the code could run without it. I would also try to find a more efficient way to add information about the planets. Creating a large hash for each planet seemed a little code heavy and I wonder if there’s a way I could do it differently. I would have also used faker to save time instead of looking up real facts about the planets.