diff --git a/lib/.DS_Store b/lib/.DS_Store new file mode 100644 index 00000000..28233d6d Binary files /dev/null and b/lib/.DS_Store differ diff --git a/lib/main.rb b/lib/main.rb new file mode 100644 index 00000000..bb62353f --- /dev/null +++ b/lib/main.rb @@ -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 diff --git a/lib/planet.rb b/lib/planet.rb new file mode 100644 index 00000000..97b918f6 --- /dev/null +++ b/lib/planet.rb @@ -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" diff --git a/lib/solar_system.rb b/lib/solar_system.rb new file mode 100644 index 00000000..60e4ccaf --- /dev/null +++ b/lib/solar_system.rb @@ -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")