-
Notifications
You must be signed in to change notification settings - Fork 47
solar_system Yasmin Leaves #43
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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') | ||
| puts "\n#{earth.summary}" | ||
| puts "\n#{mars.summary}" | ||
| puts "\n#{neptune.summary}" | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| 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 | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
|
|
||
|
|
||
| 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 | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
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.