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 - Val - Edges #31

Open
wants to merge 15 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
66 changes: 66 additions & 0 deletions main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
require_relative 'planet'
require_relative 'solar_system'

# Wave 3 Driver Code
def main
solar_system = SolarSystem.new('Sun')

earth = Planet.new('Earth', 'blue-green', 5.972e24, '149.6 mil', 'Only planet known to support life')
solar_system.add_planet(earth)

mars = Planet.new('Mars', 'red', 6.39e23, '227.9 mil', 'Second smallest planet in the solar system')
solar_system.add_planet(mars)

venus = Planet.new('Venus', 'red-brown', 4.867e24, '108.2 mil', 'Second brightest object in the night sky')
solar_system.add_planet(venus)


options = ["add planet", "planet details", "list planets", "exit"]

puts "What would you like to do?"
puts "Please choose from the following options:"
puts options
command = gets.chomp.downcase

while options.include? command
case command
when "add planet"
puts solar_system.new_planet
when "planet details"
puts solar_system.planet_details.summary
when "list planets"
puts solar_system.list_planets
when "exit"
exit
end

puts "What would you like to do next?"
command = gets.chomp.downcase
end
end

main
# Wave 1 & 2 Driver Code
# def main
# earth = Planet.new('Earth', 'blue-green', 5.972e24, 1.496e8, 'Only planet known to support life')
# puts earth.name
# puts earth.color
# puts earth.summary
#
# mars = Planet.new('Mars', 'red', 6.39e23, 227.9, 'Fun fact about Mars')
# puts mars.name
# puts mars.color
# puts mars.summary
#
# solar_system = SolarSystem.new('Sun')
# solar_system.add_planet(earth)
# solar_system.add_planet(mars)
# list = solar_system.list_planets
# puts list
#
# found_planet = solar_system.find_planet_by_name("Earth")
# puts found_planet.summary
#
# end
#
# main
17 changes: 17 additions & 0 deletions planet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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}. It has a mass of #{@mass_kg} kg and is #{@distance_from_sun_km} km away from the sun. Fun fact: #{@fun_fact}"
end

end
75 changes: 75 additions & 0 deletions solar_system.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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
i = 0

list = []

@planets.each do |planet|
list << "#{i += 1}. #{planet.name}"
end

puts "Planets orbiting #{@star_name}:"
return list
end


def find_planet_by_name(planet)
@planets.each do |p|

if p.name.downcase == planet.downcase
return p
end

end
end


def planet_details
puts "What planet would you like to learn about?"
input = gets.chomp

output = find_planet_by_name(input)

return output
end


def new_planet
puts "Please provide some planet information."

puts "Name:"
name = gets.chomp

puts "Color:"
color = gets.chomp

puts "Mass (kg):"
mass = gets.chomp

puts "Distance from sun (km):"
distance = gets.chomp

puts "Fun fact:"
fun_fact = gets.chomp

new_planet = Planet.new(name, color, mass, distance, fun_fact)
add_planet(new_planet)

return "Planet added!"
end

end