From 1b79332a3315088a1df00db348c2147432bd5262 Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Tue, 14 Feb 2017 22:59:40 -0800 Subject: [PATCH 1/2] Create solar_system.rb --- solar_system.rb | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 solar_system.rb diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..5919964f --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,60 @@ +class Planet + attr_accessor :name, :diameter, :mass, :moons, :rings, :rotation, :distance_from_the_sun + + def initialize (name,diameter,mass,moons,rings,rotation,distance_from_the_sun) + @name = name + @diameter = diameter + @mass = mass + @moons = moons + @rings = rings + @rotation = rotation + @distance_from_the_sun = distance_from_the_sun + end + + def print_name + puts "I'm a Planet whose name is #{ @name } that has a diameter of #{ @diameter }, a mass of #{ @mass }, + #{ @moons } moons, #{ @rings } rings, and has a rate of solar rotation of #{ @rotation }. + My distance from the sun is #{ @distance_from_the_sun }." + end + +end + +earth = Planet.new("Earth","7917 mi","5.972 × 10^24 kg","1","0","24 days","i") +jupiter = Planet.new("Jupiter","86,881.4 mi","1.898 × 10^27 kg","67","4","9 hours","i") +venus = Planet.new("Venus","7520 mi","4.867 × 10^24 kg","0","0","i","i") + +planets = [earth, jupiter, venus] + +planets.each do |planet| + print planet.name + " : " + planet.print_name +end + +class SolarSystem + attr_reader :galaxy_name, :planets, :formation_year + def initialize (galaxy_name,formation_year) + @galaxy_name = galaxy_name + @planets = [] + @formation_year = formation_year + end + + def add_planets(planet_name) + @planets << planet_name + end + + # def print_system + # puts "This system is the #{ @galaxy_name }, it has a formation + # year of # { @formation_year } ago." + +end + +milky_way = SolarSystem.new("Milky Way","13.6 billion years") +puts "This system is the #{ milky_way.galaxy_name }, it has a formation +year of #{ milky_way.formation_year } ago." + +planets.each do |planet| + milky_way.add_planets(planet) + # planets.print_system +end + +milky_way.planets From 1d2bcb9cb1b7857e4777b5e5aa8590d980861a0d Mon Sep 17 00:00:00 2001 From: Haby Randall Date: Thu, 16 Feb 2017 09:41:28 -0800 Subject: [PATCH 2/2] solar_system.rb --- solar_system.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/solar_system.rb b/solar_system.rb index 5919964f..2557323c 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -1,6 +1,7 @@ +require 'colorize' class Planet attr_accessor :name, :diameter, :mass, :moons, :rings, :rotation, :distance_from_the_sun - + def initialize (name,diameter,mass,moons,rings,rotation,distance_from_the_sun) @name = name @diameter = diameter @@ -10,13 +11,13 @@ def initialize (name,diameter,mass,moons,rings,rotation,distance_from_the_sun) @rotation = rotation @distance_from_the_sun = distance_from_the_sun end - + def print_name puts "I'm a Planet whose name is #{ @name } that has a diameter of #{ @diameter }, a mass of #{ @mass }, #{ @moons } moons, #{ @rings } rings, and has a rate of solar rotation of #{ @rotation }. My distance from the sun is #{ @distance_from_the_sun }." end - + end earth = Planet.new("Earth","7917 mi","5.972 × 10^24 kg","1","0","24 days","i") @@ -37,20 +38,20 @@ def initialize (galaxy_name,formation_year) @planets = [] @formation_year = formation_year end - + def add_planets(planet_name) @planets << planet_name end - + # def print_system # puts "This system is the #{ @galaxy_name }, it has a formation # year of # { @formation_year } ago." - + end milky_way = SolarSystem.new("Milky Way","13.6 billion years") puts "This system is the #{ milky_way.galaxy_name }, it has a formation -year of #{ milky_way.formation_year } ago." +year of #{ milky_way.formation_year } ago.".colorize(:blue) planets.each do |planet| milky_way.add_planets(planet)