diff --git a/main.rb b/main.rb new file mode 100644 index 00000000..42ed507a --- /dev/null +++ b/main.rb @@ -0,0 +1,64 @@ +require_relative "solar_system" +require_relative "planet" + +def main + sol_system = SolarSystem.new("Sol") + gem_homeland = Planet.new("Gem Homeland", "crystal", 78939, 287200, "Home of the Crystal Gems.") + sol_system.add_planet(gem_homeland) + + venus = Planet.new("Venus", "purple", 78939, 2000, "The brightest object in our solar system after the sun and the moon. ") + sol_system.add_planet(venus) + + earth = Planet.new("Earth", "blue", 100.25, 5000, "I live here!") + sol_system.add_planet(earth) + + mars = Planet.new("Mars", "red", 78939, 2000, "John Jones is from there") + sol_system.add_planet(mars) + + jupiter = Planet.new("Jupiter", "yellow", 78939, 2000, "The fastest rotating planet in the solar system.") + sol_system.add_planet(jupiter) + + saturn = Planet.new("Saturn", "purple with rings", 78939, 2000, "My fav planet!") + sol_system.add_planet(saturn) + + uranus = Planet.new("Uranus", "orange", 78939, 2000, "lol") + sol_system.add_planet(uranus) + + neptune = Planet.new("Neptune", "green", 78939, 2000, "Not to be confused with the King of Bikini Bottom.") + sol_system.add_planet(neptune) + + list = sol_system.list_planets + + puts sol_system.list_planets_one + #will return a summary of the planet you put in the argument + # sol_system.find_planet_by_name_two("maRs").summary + + puts "Would you like a list of planets, planet details, to add a planet, or to exit?" + puts "Enter (list), (details), (add), or (exit)." + puts "Enter List to continue or exit to end the program" + + # gets user input + + loop do + list = sol_system.list_planets + input = gets.chomp.downcase + break if input == "exit" + + case input + when "list" + puts list + when "details" + puts "What planet do you want details for?" + details = gets.chomp.downcase + puts sol_system.find_planet_by_name_two(details).summary + when "add" + sol_system.new_planet + puts sol_system.list_planets + end + break + end + + puts "Goodbye!" +end + +main diff --git a/planet.rb b/planet.rb new file mode 100644 index 00000000..dfb91442 --- /dev/null +++ b/planet.rb @@ -0,0 +1,17 @@ +class Planet + attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact + + def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact) + @name = name + @color = color + @mass_kg = mass_kg + @distance_from_sun_km = distance_from_sun_km + @fun_fact = fun_fact + end + + def summary + return "#{name}: is the color #{color}, weighs #{mass_kg}kg, and is #{distance_from_sun_km}km from the sun. Fun fact: #{fun_fact} " + end +end + +earth = Planet.new("Earth", "green", 100.25, 5000, "I live here!") diff --git a/planet_spec.rb b/planet_spec.rb new file mode 100644 index 00000000..a43310d9 --- /dev/null +++ b/planet_spec.rb @@ -0,0 +1,14 @@ +require "minitest/autorun" +require "minitest/reporters" +require_relative "planet" + +Minitest::Reporters.use! + +describe "planet" do + it "will return a string" do + home_planet = earth.summary + earth = Planet.new("Earth", "green", 100.25, 5000, "I live here!") + + expect(home_planet).must_be_instance_of String + end +end diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..3f2df2df --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,58 @@ +class SolarSystem + attr_reader :star_name, :planets + + def initialize(star_name) + @star_name = star_name + @planets = [] + end + + # Create a method add_planet, + #which will take an instance of Planet as a parameter and add it to the list of planets. + def add_planet(planet) #Planet.name + #iterate through each Planet.name and put it in the @planets array. + @planets << planet + end + + def list_planets + result = "Planets orbitting:\n" + planet_names = @planets.map do |planet| + planet.name + end + planet_names.each_with_index do |name, index| + result += "#{index + 1}. #{name}\n" + end + return result + # @planets.name specify that you're searching the name + end + + def list_planets_one + result = "Planets orbitting:\n" + @planets.each_with_index do |planet, index| + result += "#{index + 1}. #{planet.name}\n" + end + return result + end + + def find_planet_by_name_two(name) + return @planets.find do |planet| + planet.name.downcase == name.downcase + end + end + + def new_planet + puts "Add planet name:" + name = gets.chomp.downcase + puts "Add color:" + color = gets.chomp + puts "Add mass in kg:" + mass_kg = gets.chomp.to_i + puts "Distance from the sun?" + distance_from_sun_km = gets.chomp.to_i + puts "What is a fun fact about your planet?" + fun_fact = gets.chomp + user_input_planet = (Planet.new(name, color, mass_kg, distance_from_sun_km, fun_fact)) + # planet(user_input_planet) + # puts sol_system.new_planet.summary + add_planet(user_input_planet) + end +end