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

Solar System Submission #30

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
Empty file added .idea/.gitignore
Empty file.
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.

54 changes: 54 additions & 0 deletions .idea/workspace.xml

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

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

def main
earth = Planet.new('Earth', 'blue-green', 5.972e24, 1.496e8, 'Only planet known to support life')
mars = Planet.new('Mars', 'red', 6.4169e23, 2.2794e8, 'Mars had water in the ancient past')

solar_system = SolarSystem.new('Sun')

solar_system.add_planet(earth)
solar_system.add_planet(mars)

list = solar_system.list_planets


def user_choice
puts "What do you like to do?"
puts "- list planets"
puts "- planet details"
puts "- add planet"
puts "- exit"
end

def line
puts "-" * 40
end


line
puts "Welcome to Solar System Planets"
line
user_choice


user_input = gets.chomp
until user_input == "exit"

if user_input == "list planets"
puts list
line
user_choice
user_input = gets.chomp

elsif user_input == "planet details"
puts "Please enter the name of the Planet you like to know more about"
user_planet_choice = gets.chomp
found_planet = solar_system.find_planet_by_name(user_planet_choice)
if found_planet
puts found_planet.summary
user_choice
user_input = gets.chomp
else
puts "planet not found!"
end

elsif user_input == "add planet"
puts "please enter the planet's name"
planet_name = gets.chomp
puts "please enter the planet's color"
planet_color = gets.chomp
puts "please enter the planet's mass in kg"
planet_mass = gets.chomp
puts "please enter the planet's distance from sun in km"
planet_sun_distance = gets.chomp
puts "please enter a fun fact about this planet"
planet_fun_fact= gets.chomp

user_planet = Planet.new(planet_name, planet_color, planet_mass, planet_sun_distance, planet_fun_fact)

solar_system.add_planet(user_planet)
list = solar_system.list_planets

line
user_choice
user_input = gets.chomp
end
end
end

main
16 changes: 16 additions & 0 deletions planet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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 that has a mass of #{mass_kg} and a distance of #{distance_from_sun_km} km away from the Sun. Fun fact: #{fun_fact} ."
end

end
33 changes: 33 additions & 0 deletions solar_system.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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
all = "Planets orbiting #{@star_name}"
@planets.each_with_index do |planet,i|
all += "\n"
all += "#{i+1}. #{planet.name}"
end
return all
end

def find_planet_by_name(name)
@planets.each do |planet|
if planet.name.downcase == name.downcase
return planet
else
return false
end
end
end


end