Skip to content

Commit

Permalink
Created planet.rb, solar_system.rb, and main.rb to display name of pl…
Browse files Browse the repository at this point in the history
…anet -Wave 2 completed requirement 4
  • Loading branch information
lebaongoc committed Feb 26, 2019
1 parent 8cdabfb commit 1ab54b6
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
Binary file added lib/.DS_Store
Binary file not shown.
18 changes: 18 additions & 0 deletions lib/main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require_relative "planet.rb"
require_relative "solar_system.rb"

def main
solar_system = SolarSystem.new("Sun")

mercury = Planet.new("Mercury", "dark grey", 4.867e24, 5.791e7, "Mercury is the smallest plannet in our solar system")
solar_system.add_planet(mercury)

saturn = Planet.new("Saturn", "yellowish-brown", 5.683e26, 1.434e9, "Saturn is the second largest planet in our solar system")
solar_system.add_planet(saturn)

list = solar_system.list_planets

puts list
end

main
22 changes: 22 additions & 0 deletions lib/planet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Planet
attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact

def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact)
@name = name
@color = color
@mass_kg = mass_kg
@distance_from_sun_km = distance_from_sun_km
@fun_fact = fun_fact
end

def summary
return "Planet #{name} has the color of #{color} with the mass of #{mass_kg} kgs. This planet is #{distance_from_sun_km} km from the sun. A fun-fact about this planet is: #{fun_fact}"
end
end

# earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life")

# puts earth.name
# puts earth.fun_fact

# earth.color = "pink"
37 changes: 37 additions & 0 deletions lib/solar_system.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

class SolarSystem
attr_reader :star_name, :planet

def initialize(star_name)
@star_name = star_name
@planets = []
end

def add_planet(planet_instance)
@planets << planet_instance
end

def list_planets
conclusion_statement = "Planets orbiting #{star_name}:\n"

i = 1
planet_list = ""
@planets.each do |planet|
planet_list += "#{i}.#{planet.name} \n"
i += 1
end

return conclusion_statement + planet_list
end

def find_planet_by_name(planet_name)
lower_case_planet_name = planet_name.downcase
@planets.each do |planet|
if planet == lower_case_planet_name
return planet
end
end
end
end

# earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life")

0 comments on commit 1ab54b6

Please sign in to comment.