forked from Ada-C11/Solar-System
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created planet.rb, solar_system.rb, and main.rb to display name of pl…
…anet -Wave 2 completed requirement 4
- Loading branch information
Showing
4 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require_relative "planet.rb" | ||
require_relative "solar_system.rb" | ||
|
||
def main | ||
solar_system = SolarSystem.new("Sun") | ||
|
||
mercury = Planet.new("Mercury", "dark grey", 4.867e24, 5.791e7, "Mercury is the smallest plannet in our solar system") | ||
solar_system.add_planet(mercury) | ||
|
||
saturn = Planet.new("Saturn", "yellowish-brown", 5.683e26, 1.434e9, "Saturn is the second largest planet in our solar system") | ||
solar_system.add_planet(saturn) | ||
|
||
list = solar_system.list_planets | ||
|
||
puts list | ||
end | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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} has the color of #{color} with the mass of #{mass_kg} kgs. This planet is #{distance_from_sun_km} km from the sun. A fun-fact about this planet is: #{fun_fact}" | ||
end | ||
end | ||
|
||
# earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") | ||
|
||
# puts earth.name | ||
# puts earth.fun_fact | ||
|
||
# earth.color = "pink" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
class SolarSystem | ||
attr_reader :star_name, :planet | ||
|
||
def initialize(star_name) | ||
@star_name = star_name | ||
@planets = [] | ||
end | ||
|
||
def add_planet(planet_instance) | ||
@planets << planet_instance | ||
end | ||
|
||
def list_planets | ||
conclusion_statement = "Planets orbiting #{star_name}:\n" | ||
|
||
i = 1 | ||
planet_list = "" | ||
@planets.each do |planet| | ||
planet_list += "#{i}.#{planet.name} \n" | ||
i += 1 | ||
end | ||
|
||
return conclusion_statement + planet_list | ||
end | ||
|
||
def find_planet_by_name(planet_name) | ||
lower_case_planet_name = planet_name.downcase | ||
@planets.each do |planet| | ||
if planet == lower_case_planet_name | ||
return planet | ||
end | ||
end | ||
end | ||
end | ||
|
||
# earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") |