From e7c88180a4f30bdac13c692e3cb604a7c9706d40 Mon Sep 17 00:00:00 2001 From: Kari Bancroft Date: Mon, 28 Sep 2015 08:48:00 -0700 Subject: [PATCH 1/7] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7cf009e6..0f88e670 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Let's make a planetary system! - `1. Mercury, 2. Venus, 3. Earth, 4. Secret Earth, 5. Mars, 6. Jupiter, ... 13. Exit` - Provide the user with well formatted information about the planet (diameter, mass, number of moons, primary export, etc.) - Then ask the user for another planet. - + From 76f6bc20f152e61184ec6734ccfaf1b3e994416e Mon Sep 17 00:00:00 2001 From: Kari Bancroft Date: Mon, 28 Sep 2015 08:48:48 -0700 Subject: [PATCH 2/7] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0f88e670..2e906a61 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Let's make a planetary system! - `1. Mercury, 2. Venus, 3. Earth, 4. Secret Earth, 5. Mars, 6. Jupiter, ... 13. Exit` - Provide the user with well formatted information about the planet (diameter, mass, number of moons, primary export, etc.) - Then ask the user for another planet. + From 0120ff19014d9caa13210565a1dc4abf16e91062 Mon Sep 17 00:00:00 2001 From: Kari Bancroft Date: Tue, 29 Sep 2015 09:14:10 -0700 Subject: [PATCH 6/7] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 3f82aec6..7e3aee8f 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ Let's make a planetary system! - Create a `SolarSystem` class that has an attribute `planets` that has zero to many `Planet` instances. To create the Planet associations, your `SolarSystem` should: - Have a method that adds a single planet to your solar system - Have a second method that adds an array of planets to the existing array of planets +- Update your `initialize` in the `Planet` class to accept a hash rather than individual parameters +- Use a default value attribute in at least one method in your `Planet` class ## Optional Enhancements - If you haven't already, add a `@distance_from_the_sun` attribute to your `Planet`. Using this data, add a method to your `SolarSystem` which will calculate the distance between any two planets provided (assuming planets are in a straight line from the sun) From db8a3d738da45bb1b18cd23970905c43ef881dcd Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 26 Feb 2016 09:42:24 -0800 Subject: [PATCH 7/7] solar-system --- planet.rb | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 planet.rb diff --git a/planet.rb b/planet.rb new file mode 100644 index 00000000..cc458f2d --- /dev/null +++ b/planet.rb @@ -0,0 +1,70 @@ +class SolarSystem + attr_reader :planets + + def intialize(planets) + planets.each do |planet| + @planets[planet.name] = planet + end + end + + def add_planet(x) + @planets[x.name] = x + end + + def remove_planet(planet_name) + @planets[planet_name] = nil + end + + def name_of_planet(position) + planet_in_position = @planets[position] + + planet_in_position.class #=> Planet + planet_in_position.colonized? #=> true or false + @planets[position].name + end + + def distance_between(planet1, planet2) + + end +end + +class Planet + attr_reader :name, :earth_age + + def initialize(options) + @name = options[:name] + @mass = options[:mass] + @rotation = options[:rotation] + @earth_age = options[:earth_age] + @distance = options[:distance] + @robots = options[:robots] + end + + def colonized? + @robots == true + end +end + + +earth = Planet.new(name: "Earth", mass: 32598234, robots: true) +mars = Planet.new(name: "Earth", mass: 23455, robots: true) +solar_system = SolarSystem.new(name: "Our solar system", planets: [earth, mars]) + +venus = Planet.new(name: "Venus", mass: 2343284092384, robots: true) +planet_dog_food = Planet.new(name: "Dog Food", mass 0, robots: false) + +solar_system.add_planet(venus) +solar_system.add_planet(planet_dog_food) + + + +planets = { + "mercury" => Planet.new(), + "venus" => Planet.new() +} +choice = gets.chomp.downcase +planets[choice] + + + +