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

Earth - Emily #38

Open
wants to merge 2 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
15 changes: 15 additions & 0 deletions Planet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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: #{@name}. #{@name.capitalize}'s color is #{@color}. This planet's mass is #{@mass_kg} and #{@distance_from_sun_km} million km away from the sun. An interesting fact is that #{@fun_fact}."
end
end
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The learning goal for this wave is to practice working with individual instances

```ruby
# Load Planet into pry:
# $ pry -r ./planet.rb
# $ pry -r ./Planet.rb
earth = Planet.new('Earth', 'blue-green', 5.972e24, 1.496e8, 'Only planet known to support life')

puts earth.name
Expand Down
50 changes: 50 additions & 0 deletions Solar_System.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class SolarSystem
attr_reader :star_name, :planets

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

end

def add_planet(planet)
@planets << planet
end

#Taking string, planet, and returning instance planet by
# pushing into an instance variable array
def list_planets
puts "Planets orbiting #{star_name}:"

@planets.each_with_index do |planet, i|
@list_of_planets << "#{i+1}. #{planet.name}"
end
return @list_of_planets
end

def find_planet_by_name(planet_name)
@planets.each do |planet|
if planet == planet_name
return planet.summary
end
end
return "Invalid planet."
end

def add_new_planet
print "Which planet would you like to add? > "
new_planet_name = gets.chomp
print "What's the color? > "
new_planet_color = gets.chomp
print "What's the mass? > "
new_planet_mass = gets.chomp
print "Distance from the sun? > "
new_planet_distance = gets.chomp
puts "What about a fun fact?:"
new_planet_fact = gets.chomp.capitalize

new_planet = Planet.new(new_planet_name, new_planet_color, new_planet_mass, new_planet_distance, new_planet_fact)
add_planet(new_planet)
end
end
46 changes: 46 additions & 0 deletions main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require_relative "Planet"
require_relative "Solar_System"

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

mercury = Planet.new( 'Mercury', 'dark gray', 3.285e23, 57.9, 'Mercury is shrinking!')
solar_system.add_planet(mercury)

venus = Planet.new('Venus', 'white', 4.867e24, 108.2, 'A day on Venus is longer than a year')
solar_system.add_planet(venus)

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

mars = Planet.new('Mars', 'red', 6.39e24, 227.9, 'Pieces of Mars have fallen to Earth')
solar_system.add_planet(mars)

jupiter = Planet.new('Jupiter', 'white-orange-red', 1.898e27, 778.3, 'Jupiter has the shortest day of all the planets')
solar_system.add_planet(jupiter)

run_solar_system = true
puts "Enter: list planets | planet details | add planet | exit"

while run_solar_system
user_input = gets.chomp
if user_input == "exit"
puts "Have a great day!"
return run_solar_system == false
elsif user_input == "list planets"
puts solar_system.list_planets
puts "Enter planet details to learn more or enter exit"
elsif user_input == "planet details"
puts "You picked planet details!"
puts "Which planet do you want to learn about?"
planet_name = gets.chomp
puts solar_system.find_planet_by_name(planet_name) #not working
elsif user_input == "add planet"
solar_system.add_new_planet
else
puts "Invalid prompt"
end
end
end

main