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

Taylor/Solar-System #39

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
62 changes: 62 additions & 0 deletions main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require_relative "planet"
require_relative "solar_system"

def main

solar_system = SolarSystem.new("Orion")

mars = Planet.new("Mars", "red", "6.39 × 10^23", "210.58 million", "we might have to figure out how to live there if corporations keep ruining earth")
solar_system.add_planet(mars)
venus = Planet.new("Venus", "yellowish white", "4.867 × 10^24", "107.85 million", "doesn't have any moons :( ")
solar_system.add_planet(venus)
titan = Planet.new("Titan", "glowing orange", "1.3452 x 1023", "1.4 billion", "Kurt Vonnegut wrote a great book that was set on this planet")
solar_system.add_planet(titan)




control_loop(solar_system)
end
def control_loop(solar_system)

puts "Options:\nList Planets\nPlanet Details\nAdd Planet\nExit"

choice = ""
until choice == "exit" do

puts "\nWhat would you like to do?\n"
choice = gets.chomp.downcase

case choice
when "list planets"
puts solar_system.list_planets
when "planet details"
puts "What planet would you like to know more about?"
planet = gets.chomp.capitalize
puts solar_system.find_planet_by_name(planet)
when "add planet"
puts "What's the name of the planet you want to add?"
user_planet = gets.chomp.capitalize
puts "Color?"
color = gets.chomp
puts "Mass in kg?"
mass = gets.chomp
puts "Distance from the sun?"
distance = gets.chomp
puts "Fun fact?"
funfact = gets.chomp

solar_system.add_planet(Planet.new(user_planet, color, mass, distance, funfact))



else
exit
end
end
end




main
19 changes: 19 additions & 0 deletions planet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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 #{color} and has a mass of #{mass_kg} kg. This planet is #{distance_from_sun_km} kilometers from the sun and #{fun_fact}! Cool!"
end

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

class SolarSystem

attr_reader :star_name, :planets

attr_accessor :planets

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

#takes instance of Planet as parameter?
def add_planet(planet_instance)
@planets << planet_instance
end
# return string drop down list of planets
def list_planets
@planets_list = ["Planets orbiting #{star_name}:\n"]
i = 0
@planets.length.times do
list_item = "#{i + 1}. #{@planets[i].name}\n"
@planets_list << list_item
i += 1
end
return @planets_list
end

def find_planet_by_name(planet_name)

@planets.each do |planet|
if planet_name == planet.name
return planet.summary
end
raise ArgumentError.new("Hmm..that planet isn't in this solar system.")
end
end

end