diff --git a/Solar_System_2.rb b/Solar_System_2.rb new file mode 100644 index 00000000..a4e99a0b --- /dev/null +++ b/Solar_System_2.rb @@ -0,0 +1,99 @@ +require "./planet_class" +require "./solar_class" + +mercury_hash = { + name: "Mercury", + diameter: 3031, + distance_from_sun: 36, + number_of_moons: 0, + solar_rotation: 0.24 +} + +venus_hash = { + name: "Venus", + diameter: 7521, + distance_from_sun: 67, + number_of_moons: 0, + solar_rotation: 0.62 +} + +earth_hash = { + name: "Earth", + diameter: 7926, + distance_from_sun: 93, + number_of_moons: 1, + solar_rotation: 365.24 +} + +mars_hash = { + name: "Mars", + diameter: 4217, + distance_from_sun: 93, + number_of_moons: 1, + solar_rotation: 697 +} + +jupiter_hash = { + name: "Jupiter", + diameter: 88730, + distance_from_sun: 484, + number_of_moons: 16, + solar_rotation: 11.6 +} + +saturn_hash = { + name: "Saturn", + diameter: 74900, + distance_from_sun: 888, + number_of_moons: 18, + solar_rotation: 29.5 +} + +uranus_hash = { + name: "Uranus", + diameter: 31763, + distance_from_sun: 1780, + number_of_moons: 17, + solar_rotation: 84 +} + +neptune_hash = { + name: "Neptune", + diameter: 31775, + distance_from_sun: 2800, + number_of_moons: 16, + solar_rotation: 165 +} + +mercury = Planet.new(mercury_hash) +venus = Planet.new(venus_hash) +earth = Planet.new(earth_hash) +mars = Planet.new(mars_hash) +jupiter = Planet.new(jupiter_hash) +saturn = Planet.new(saturn_hash) +uranus = Planet.new(uranus_hash) +neptune = Planet.new(neptune_hash) + + +original_planets = [] +original_planets.push(mercury) +original_planets.push(venus) +original_planets.push(earth) +original_planets.push(mars) +original_planets.push(jupiter) +original_planets.push(saturn) +original_planets.push(uranus) +original_planets.push(neptune) + +milky_way_hash = { + name: "Milky Way" +} + +milky_way = Solar_System.new(milky_way_hash) + +milky_way.add_many_planets(original_planets) + +milky_way.print_planets + + +#milky_way.distance_away(mercury, neptune) diff --git a/Solar_System_Wave1.rb b/Solar_System_Wave1.rb new file mode 100644 index 00000000..b5d4149c --- /dev/null +++ b/Solar_System_Wave1.rb @@ -0,0 +1,59 @@ +class Planet + attr_accessor :name, :diameter, :distance_from_sun, :number_of_moons, :solar_rotation + + def initialize(name, diameter, distance_from_sun, number_of_moons, solar_rotation) + @name = name + @diameter = diameter + @distance_from_sun = distance_from_sun + @number_of_moons = number_of_moons + @solar_rotation = solar_rotation + end + + def print_out + puts "Let's talk about #{@name}." + puts "\n" + puts "#{@name} has a diameter of #{@diameter} and #{@number_of_moons} moons. It is #{@distance_from_sun} miles away from the sun, rotating around the sun for #{@solar_rotation} earth years in one rotation." + puts "\n\n\n" + end + +end + +mercury = Planet.new("Mercury", 3031, 36, 0, 0.24) +venus = Planet.new("Venus", 7521, 67, 0, 0.62) +earth = Planet.new("Earth", 7926, 93, 1, 365.24) +mars = Planet.new("Mars", 4217, 142, 2, 697) +jupiter = Planet.new("Jupiter", 88730, 484, 16, 11.9) +saturn = Planet.new("Saturn", 74900, 888, 18, 29.5) +uranus = Planet.new("Uranus", 31763, 1780, 17, 84) +neptune = Planet.new("Neptune", 31775, 2800, 16, 165) +pluto = Planet.new("Pluto", "n/a", "n/a", "n/a", "n/a") + +nets = [] +nets.push(mercury, venus, earth, mars, jupiter, saturn, uranus, neptune) + + +def call_to_planets(planet_array) + puts "Hello! Check out the available planets to learn about:" + line_width = 60 + count = 1 + planet_array.each do |planet| + puts "#{count}. #{planet.name}".center(line_width) + count += 1 + end + puts "Which one interests you? Type the number or \"exit\" to quit:" + response = gets.chomp + return response +end + +user_choice = call_to_planets(nets) + + +while user_choice.downcase != "exit" + puts "I can't do this off the top of my head. Let me consult my planet dictionary..." + + nets[user_choice.to_i - 1].print_out + + user_choice = call_to_planets(nets) +end + +puts "Hope you learned something! Even if it was just that Pluto is not a planet. RIP" diff --git a/planet_class.rb b/planet_class.rb new file mode 100644 index 00000000..511fe08b --- /dev/null +++ b/planet_class.rb @@ -0,0 +1,23 @@ +class Planet + attr_accessor :name, :diameter, :distance_from_sun, :number_of_moons, :solar_rotation, :badass + + def initialize(planet_hash, badass = true) + @name = planet_hash[:name] + @diameter = planet_hash[:diameter] + @distance_from_sun = planet_hash[:distance_from_sun] + @number_of_moons = planet_hash[:number_of_moons] + @solar_rotation = planet_hash[:solar_rotation] + @badass = planet_hash[:badass] + end + + def print_out + puts "Let's talk about #{@name}." + puts "\n" + puts "#{@name} has a diameter of #{@diameter} and #{@number_of_moons} moons. It is #{@distance_from_sun} miles away from the sun, rotating around the sun for #{@solar_rotation} earth years in one rotation." + if badass == false + puts "Interestingly, this planet that is not badass at all. That is rare, and most likely due to its frigid temperatures, which make me sad." + end + puts "\n\n\n" + end + +end diff --git a/solar_class.rb b/solar_class.rb new file mode 100644 index 00000000..4dfbc386 --- /dev/null +++ b/solar_class.rb @@ -0,0 +1,31 @@ +class Solar_System + attr_accessor :planets, :name + + def initialize(solar_hash) + @name = solar_hash[:name] + @planets = [] + end + + def add_many_planets(planet_array) + planet_array.each do |plan| + @planets.push(plan) + puts plan.name + end + end + + def add_one_planet(planet_hash) + @planets.push(planet_hash) + end + + def print_planets + @planets.length.times do |num| + puts "#{num + 1}. #{@planets[num].name}" + end + end + + def distance_away(planet_a, planet_b) + distance =(planet_a.distance_from_sun - planet_b.distance_from_sun).abs + puts "The distance between #{planet_a.name} and #{planet_b.name} is #{distance} of some units I forget. Won't mean much anyway. On with your day." + end + +end