diff --git a/main.rb b/main.rb new file mode 100644 index 00000000..57bce4f7 --- /dev/null +++ b/main.rb @@ -0,0 +1,50 @@ +require_relative "planet" +require_relative "solar_system" +require "pry" + +def main + solar_system = SolarSystem.new("Phunghoule") + + bebop = Planet.new(name: "Bebop", color: "gray", mass_kg: 5, distance_from_sun_km: 2.2, fun_fact: "Bebop's nickname is Mrs. Tubbins!") + ninou = Planet.new(name: "Ninou", color: "black", mass_kg: 3, distance_from_sun_km: 2.2, fun_fact: "Ninou is the best planet ever!") + andrew = Planet.new(name: "Andrew", color: "white", mass_kg: 91, distance_from_sun_km: 3, fun_fact: "Andrew is full of gas") + + solar_system.add_planet(bebop) + solar_system.add_planet(ninou) + solar_system.add_planet(andrew) + + loop do + puts "Choose your next adventure: " + puts "\ntype LIST to see a list of all planets, " + puts "type LEARN to learn about the planets," + puts "type ADD to create your own planet, or" + puts "type EXIT to quit" + + selection = gets.chomp.downcase + + case selection + when "exit" + puts "Goodbye." + exit + when "list" + puts "#{solar_system.list_planets}" + when "learn" + puts "#{solar_system.list_planets}" + puts "Type the name of the planet you want to learn about: " + learn_choice = gets.chomp.capitalize! + + solar_system.planets.each_with_index do |planet, index| + puts "#{planet.name}" + if planet.name == learn_choice + puts "#{planet.summary}" + end + end + when "add" + solar_system.add_planet_details + puts "Thanks! Your planet has been added to the solar system: " + puts "#{solar_system.list_planets}" + end + end +end + +main diff --git a/planet.rb b/planet.rb new file mode 100644 index 00000000..377f31d9 --- /dev/null +++ b/planet.rb @@ -0,0 +1,19 @@ +class Planet + attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact + + def initialize(name: "", color: "", mass_kg: 0, distance_from_sun_km: 0, 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 "The planet, #{@name} is #{@color} in color, its mass is #{@mass_kg}kg, has a distance of #{@distance_from_sun_km}km from sun, fun fact: #{@fun_fact}" + end +end + +ARIEL = Planet.new(name: "Ariel", color: "blue-ish", mass_kg: 6455783, distance_from_sun_km: 308546069, fun_fact: "Ariel has an extensive network of medical-related industries.") + +LONDINIUM = Planet.new(name: "Londinium", color: "green-ish", mass_kg: 1236620, distance_from_sun_km: 1346380, fun_fact: "Londinium is where the Parliament is housed.") diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..f6e27723 --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,47 @@ +class SolarSystem + attr_reader :star_name, :planets + + def initialize(star_name) + @star_name = star_name + @planets = [] + end + + def add_planet_details + puts "Enter the new planet's name: " + name = gets.chomp.capitalize + puts "Color of the planet: " + color = gets.chomp.downcase + puts "Mass in kilograms: " + mass = gets.chomp.to_i + puts "Distance from the sun in kg" + distance = gets.chomp.to_i + puts "A fun fact about the planet: " + fun_fact = gets.chomp.capitalize + + new_planet = Planet.new(name: "#{name}", color: "#{color}", mass_kg: mass, distance_from_sun_km: distance, fun_fact: "#{fun_fact}") + + add_planet(new_planet) + end + + def add_planet(planet) + @planets.push(planet) + return planet + end + + def list_planets + list_of_planets = "Planets orbiting #{@star_name}" + @planets.each_with_index do |planet, index| + list_of_planets += "\n#{index + 1}: #{planet.name}" + end + return list_of_planets + end + + def find_planet_by_name(planet_name) + @planets.each do |planet| + if planet.name.capitalize == planet_name.capitalize + return planet + end + end + return nil + end +end