Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sophia / Solar System #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/solar-system.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require_relative 'planet'
require_relative 'solar_system'

def main
solar_system = SolarSystem.new('Sol')

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

mars = Planet.new('Mars', 'red-orange', 6.39e23, 228526848, 'named after the roman god of war' )
puts mars.summary

list = solar_system.list_planets
puts list

end

main
18 changes: 18 additions & 0 deletions planet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require_relative 'solar_system'

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 "#{name} is a #{color} planet in our solar system. It has a mass of #{mass_kg} and is #{distance_from_sun_km}km from the sun. A fun fact is #{fun_fact}."
end
end
30 changes: 30 additions & 0 deletions solar_system.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require_relative 'planet'

class SolarSystem
attr_reader :star_name, :planets

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

end

def add_planet(planet)
@planets << planet
end

def list_planets
@more_planets = "Planets orbitiing #{star_name}:\n"
i = 0
@planets.each do
planet_list = "#{i+1}. #{planets[i].name}\n"
@more_planets << planet_list
i += 1
end
return @more_planets
end




end