diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..5008ddfc Binary files /dev/null and b/.DS_Store differ 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.rb b/solar_system.rb new file mode 100644 index 00000000..9aabe96e --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,48 @@ +class SolarSystem + +attr_accessor :name, :planets + + def initialize (planet_hash) + @name = planet_hash[:name] + @planets = [] + end + + def add_planet(planet) + @planets.push(planet) + end + + def add_multiple_planets(planet_array) + planet_array.each do |plan| + @planets.push(plan) + end + end + + def about + puts "Here are the planets in the #{@name} solar system:" + count = 1 + + @planets.each do |planet| + puts "#{count}. #{planet.name}" + count += 1 + end + puts "#{count}. Exit" + puts "Which planet do you want to learn about?" + learn = gets.chomp.to_i + continue = true + + while continue == true + if learn < count + planets[learn-1].about + puts "What planet do you want to learn about next?" + learn = gets.chomp.to_i + elsif learn == count + puts "Goodbye!" + continue = false + else + puts "I am sorry. I don't know what you mean. Please enter in a number from 1 to #{count-1} to learn about a planet, or #{count} to exit" + learn = gets.chomp.to_i + end + end + 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:, +# }