From c707f1afcb51e33d321e8dd7b311b7ccfc0223a0 Mon Sep 17 00:00:00 2001 From: emgord Date: Thu, 1 Oct 2015 11:23:16 -0700 Subject: [PATCH 1/2] add solar system file --- .DS_Store | Bin 0 -> 6148 bytes solar_system.rb | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 .DS_Store create mode 100644 solar_system.rb diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Mon, 12 Oct 2015 20:14:35 -0700 Subject: [PATCH 2/2] adding planets and solar system program --- planets2.rb | 24 ++++++++++++++++ solar_system_program.rb | 63 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 planets2.rb create mode 100644 solar_system_program.rb diff --git a/planets2.rb b/planets2.rb new file mode 100644 index 00000000..f063d828 --- /dev/null +++ b/planets2.rb @@ -0,0 +1,24 @@ +class Planet + + attr_accessor :name, :diameter, :mass, :number_of_moons, :color, :distance_from_the_sun + + def initialize(planet_hash) + @name = planet_hash[:name] + @diameter = planet_hash[:diameter] + @mass = planet_hash[:mass] + @color = planet_hash[:color] + @number_of_moons = planet_hash[:number_of_moons] + @distance_from_the_sun = planet_hash[:distance_from_the_sun] + end + + def number_of_moons(number_of_moons = 0) + @number_of_moons = number_of_moons + end + + def about + puts "I am a planet named #{@name}! I have a diameter of #{@diameter} meters and a mass of #{@mass} kilograms." + puts "I have #{@number_of_moons} moons and I am #{@color}." + puts "I am #{@distance_from_the_sun} meters from the sun" + end + +end diff --git a/solar_system_program.rb b/solar_system_program.rb new file mode 100644 index 00000000..f5e4d0c4 --- /dev/null +++ b/solar_system_program.rb @@ -0,0 +1,63 @@ +require "./planets2" +require "./solar_system" + +apple_hash = { + name:"Apple", + diameter: 60, + mass:4_500, + number_of_moons:0, + color:"red", + distance_from_the_sun:4000, +} + +apple = Planet.new(apple_hash) + +pear_hash = { + name: "Pear", + diameter: 20, + mass: 3000, + number_of_moons: 4, + color: "green", + distance_from_the_sun: 5000, +} + +pear = Planet.new(pear_hash) + +orange_hash = { + name: "Orange", + diameter: 10, + mass: 500, + color: "orange", + distance_from_the_sun:10000, +} + +orange = Planet.new(orange_hash) + +orange.number_of_moons + +planets_array = [] +planets_array.push(apple) +planets_array.push(pear) + +tree_hash = { + name: "Tree", +} + +tree = SolarSystem.new(tree_hash) + + +tree.add_planet(orange) + +tree.add_multiple_planets(planets_array) + +tree.about + +# Empty Hash template to create new planets +#empty_planet = { +# name:, +# diameter:, +# mass:, +# number_of_moons:, +# color:, +# distance_from_the_sun:, +# }