diff --git a/main-wave3.rb b/main-wave3.rb new file mode 100644 index 00000000..e8067d3e --- /dev/null +++ b/main-wave3.rb @@ -0,0 +1,62 @@ +# Wave 3 +# Since wave 3 required replacing the driver code in our main method, +# I choose to create another file for Wave 3. + +require_relative "planet" +require_relative "solar_system" + +def main + # Wave 3 + solar_system = SolarSystem.new("Sun") + saturn = Planet.new("Saturn", "Blue", "13.e56", "4.98e33", "Has a ring around it") + pluto = Planet.new("Pluto", "Very Blue", "45.e87", "2.34e8", "Isn't actually a planet") + neptune = Planet.new("Neptune", "Very Very Blue", "87.e45", "3.45e3", "Really cold") + + solar_system.add_planet(saturn) + solar_system.add_planet(pluto) + solar_system.add_planet(neptune) + + def planet_details(solar_system) + puts "Which planet would you like to learn about?" + planet = gets.chomp + found_planet = solar_system.find_planet_by_name(planet) + return found_planet.summary + end + + def add_planet(solar_system) + planet_details_array = [] + # puts "What are the details of this planet? Provide the following. \nname: \ncolor: \nmass_kg: \ndistance: \nfun fact:" + puts "What is the name of this planet?" + planet_details_array.push(gets.chomp) + puts "What is the color of this planet?" + planet_details_array.push(gets.chomp) + puts "What is the mass_kg of this planet?" + planet_details_array.push(gets.chomp) + puts "What is the distance of this planet from the Sun?" + planet_details_array.push(gets.chomp) + puts "What is a fun fact about this planet?" + planet_details_array.push(gets.chomp) + planet = Planet.new(planet_details_array[0], planet_details_array[1], planet_details_array[2], planet_details_array[3], + planet_details_array[4]) + return solar_system.add_planet(planet) + end + + user_input = "A" + + while user_input == "A" || user_input == "B" || user_input == "C" + puts "What would you like to do next? \nA: List planets \nB: Planet Details \nC: Add Planet \nD: Exit Program" + user_input = gets.chomp + case user_input + when "A" + puts solar_system.list_planets + when "B" + puts planet_details(solar_system) + when "C" + add_planet(solar_system) + when "D" + user_input = "D" + end + end +end + +main \ No newline at end of file diff --git a/main.rb b/main.rb new file mode 100644 index 00000000..dede7b3b --- /dev/null +++ b/main.rb @@ -0,0 +1,31 @@ +# Wave 1 +require_relative "planet" +require_relative "solar_system" + +def main + jupiter = Planet.new("Jupiter", "Orange", "5.972e23", "1.94e8", "Has a red eye full of storms") + earth = Planet.new("Earth", "Blue", "34.e39", "14", "Only planet with life") + mercury = Planet.new("Mercury", "Red", "35.e39", "10", "Hottest Planet") + venus = Planet.new("Venus", "Brown", "39.e39", "20", "2nd Hottest Planet") + mars = Planet.new("Mars", "Brown-Orange", "40.e27", "30", "Super Rocky") + + puts "\n#{earth.summary}" + + # Wave 2 + solar_system = SolarSystem.new("Sun") + solar_system.add_planet(mercury) + solar_system.add_planet(venus) + solar_system.add_planet(earth) + solar_system.add_planet(mars) + solar_system.add_planet(jupiter) + + list = solar_system.list_planets + puts list + + found_planet = solar_system.find_planet_by_name("eArTh") + puts "\n#{found_planet}" + puts "\n#{found_planet.summary}" +end + +main + diff --git a/planet.rb b/planet.rb new file mode 100644 index 00000000..3951a06c --- /dev/null +++ b/planet.rb @@ -0,0 +1,16 @@ +# Wave 1 +class Planet + def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact) + @name = name + @color = color + @mass_kg = mass_kg + @distance = distance_from_sun_km + @fun_fact = fun_fact + end + + attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact + + def summary + return "Planet #{@name} is #{@color} and #{@fun_fact}." + end +end \ No newline at end of file diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..43dfc725 --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,34 @@ + +# Wave 2 + +class SolarSystem + attr_reader = :star_name, :planets + + def initialize(star_name) + @star_name = star_name + @planets = [] + end + + def add_planet(planet) + @planets.push(planet) + end + + def list_planets + planet_array = [] + star_name = "\nPlanets orbiting #{@star_name}" + @planets.each_with_index do |planet, index| + planet_array.push("#{index + 1}. #{planet.name}") + end + return "#{star_name} \n#{planet_array.join("\n")}" + end + + def find_planet_by_name(planet_string) + @planets.each do |planet| + if planet.name.upcase == planet_string.upcase + return planet + end + end + end +end + +