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

def main
earth = Planet.new('Earth', 'blue-green', 5.972e24, 1.496e8, 'Earth is the only planet known to support life')
neptune = Planet.new("Neptune", "blue", 1.02e26, 4.495e8, 'Neptune is the Coldest Planet in the Solar System')
mars = Planet.new("Mars", "red", 6.42e23, 227.9e9, 'Pieces of Mars have been found on Earth')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could consider putting this planets in an array, and iterating over that array using each to puts each one.

puts "\n#{earth.summary}"
puts "\n#{mars.summary}"
puts "\n#{neptune.summary}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this space

#wave2

solar_system = SolarSystem.new("sun")
solar_system.add_planet(earth)
solar_system.add_planet(neptune)
solar_system.add_planet(mars)
list = solar_system.list_planets
puts list
found_planet = solar_system.find_planet_by_name('Earth')
puts found_planet
puts found_planet.summary
end
main
20 changes: 20 additions & 0 deletions planet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Wave1
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} has a #{@color} color. A fun fact about #{@name}: #{@fun_fact}."
end
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a small detail, but you should remove extra lines of code.




49 changes: 49 additions & 0 deletions solar_system.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#Wave2
class SolarSystem
attr_reader :star_name, :planets
def initialize(star_name)
@star_name = star_name
@planets = []
end

def add_planet(planet)
@planets.push(planet)
end

def list_planets
planet_names = "\nPlanets orbiting #{@star_name}"
@planets.each_with_index do |planet, index|
planet_names += "\n#{index + 1}. #{planet.name}"
end
return planet_names
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only have a single space between method definitions


def find_planet_by_name(planet_choice)
@planets.each do |planet|
if planet_choice.upcase == planet.name.upcase
return planet
end
end
end
end