From f4eff1563067df504b1c29e439dfd6e2bb2e742c Mon Sep 17 00:00:00 2001 From: KayKay-git Date: Tue, 22 Sep 2020 17:24:44 -0400 Subject: [PATCH 1/3] Wave 1 complete --- lib/main.rb | 10 ++++++++++ lib/planet.rb | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 lib/main.rb create mode 100644 lib/planet.rb diff --git a/lib/main.rb b/lib/main.rb new file mode 100644 index 00000000..2bb70317 --- /dev/null +++ b/lib/main.rb @@ -0,0 +1,10 @@ +require_relative 'planet.rb' + +def main + earth = Planet.new('Earth', 'blue-green', 5.972e24, 1.496e8, 'Only planet known to support life') + p earth.summary +end + +main + + diff --git a/lib/planet.rb b/lib/planet.rb new file mode 100644 index 00000000..83d0d8d6 --- /dev/null +++ b/lib/planet.rb @@ -0,0 +1,22 @@ +# Wave 1 +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 "Planet #{@name} is #{@color} in color, with a mass of #{@mass_kg} kg. It is #{@distance_from_sun_km} km from the sun and is currently the #{@fun_fact.downcase}." + end + +end + +earth = Planet.new('Earth', 'blue-green', 5.972e24, 1.496e8, 'Only planet known to support life') + + From b10eb8253b712f121744062dc7a352f15d9e5cfa Mon Sep 17 00:00:00 2001 From: KayKay-git Date: Tue, 22 Sep 2020 21:19:31 -0400 Subject: [PATCH 2/3] Wave 2 complete --- lib/main.rb | 22 ++++++++++++++++++++-- lib/planet.rb | 12 ++++++++---- lib/solar_system.rb | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 lib/solar_system.rb diff --git a/lib/main.rb b/lib/main.rb index 2bb70317..edb7892f 100644 --- a/lib/main.rb +++ b/lib/main.rb @@ -1,8 +1,26 @@ require_relative 'planet.rb' +require_relative 'solar_system' + def main - earth = Planet.new('Earth', 'blue-green', 5.972e24, 1.496e8, 'Only planet known to support life') - p earth.summary + mercury = Planet.new('Mercury', 'dark-grey',2.9772e23, 1.295e8, 'The closest planet to the sun') + venus = Planet.new('Venus', 'white',3.9772e23, 1.395e8, 'The second closest planet to the sun') + earth = Planet.new('Earth', 'blue-green', 5.972e24, 1.496e8, 'The only planet known to support life') + mars = Planet.new('Mars', 'red', 6.972e24, 2.496e8, 'We may live there one day') + + solar_system = SolarSystem.new('Solar') + + solar_system.add_planet(mercury) + solar_system.add_planet(venus) + solar_system.add_planet(earth) + solar_system.add_planet(mars) + + list = solar_system.list_planets + p list + + found_planet = solar_system.find_planet_by_name('Mercury') + p found_planet.summary + end main diff --git a/lib/planet.rb b/lib/planet.rb index 83d0d8d6..35901747 100644 --- a/lib/planet.rb +++ b/lib/planet.rb @@ -1,9 +1,9 @@ # Wave 1 class Planet - attr_reader :name ,:color ,:mass_kg ,:distance_from_sun_km ,:fun_fact + attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact - def initialize(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 @@ -12,11 +12,15 @@ def initialize(name ,color ,mass_kg ,distance_from_sun_km ,fun_fact) end def summary - return "Planet #{@name} is #{@color} in color, with a mass of #{@mass_kg} kg. It is #{@distance_from_sun_km} km from the sun and is currently the #{@fun_fact.downcase}." + return "Planet #{@name} is #{@color} in color, with a mass of #{@mass_kg} kg. It is #{@distance_from_sun_km} km from the sun. Fun fact: #{@fun_fact}." end end -earth = Planet.new('Earth', 'blue-green', 5.972e24, 1.496e8, 'Only planet known to support life') + + + + + diff --git a/lib/solar_system.rb b/lib/solar_system.rb new file mode 100644 index 00000000..43083fca --- /dev/null +++ b/lib/solar_system.rb @@ -0,0 +1,32 @@ +require_relative 'planet.rb' +# Wave 2 +class SolarSystem + attr_reader :star_name, :planets + + def initialize(star_name) + @star_name = star_name + @planets = [] + end + + def add_planet(planet_instance) + @planets.push(planet_instance) + end + + def list_planets + i = 1 + list = "Planets orbiting #{@star_name}:\n" + @planets.each do |planet| + list += "#{i}. #{planet.name}\n" + i += 1 + end + return list + end + + def find_planet_by_name(planet_name) + planet_found = @planets.find do |planet| + planet.name.capitalize == planet_name.capitalize + end + return planet_found + end + +end \ No newline at end of file From 2c7b988e6dd8e909fa97a9b961a8e4e44f9dcc49 Mon Sep 17 00:00:00 2001 From: KayKay-git Date: Wed, 23 Sep 2020 14:31:56 -0400 Subject: [PATCH 3/3] Wave 3 complete --- lib/main.rb | 84 ++++++++++++++++++++++++++++++++++++++++----- lib/solar_system.rb | 3 +- 2 files changed, 78 insertions(+), 9 deletions(-) diff --git a/lib/main.rb b/lib/main.rb index edb7892f..79116328 100644 --- a/lib/main.rb +++ b/lib/main.rb @@ -1,28 +1,96 @@ +# Wave 3 + require_relative 'planet.rb' require_relative 'solar_system' -def main +def build_solar_system + + solar_system = SolarSystem.new('Solar') + mercury = Planet.new('Mercury', 'dark-grey',2.9772e23, 1.295e8, 'The closest planet to the sun') venus = Planet.new('Venus', 'white',3.9772e23, 1.395e8, 'The second closest planet to the sun') earth = Planet.new('Earth', 'blue-green', 5.972e24, 1.496e8, 'The only planet known to support life') mars = Planet.new('Mars', 'red', 6.972e24, 2.496e8, 'We may live there one day') - solar_system = SolarSystem.new('Solar') - solar_system.add_planet(mercury) solar_system.add_planet(venus) solar_system.add_planet(earth) solar_system.add_planet(mars) - list = solar_system.list_planets - p list + return solar_system +end - found_planet = solar_system.find_planet_by_name('Mercury') - p found_planet.summary +def user_choice + puts "Welcome, what would you like to do?" + puts "Your choices are: list planets, planet details, add planet, or exit" + print "Choice:" + choice = gets.chomp.downcase + return choice end -main +def planet_details + puts "Which planet would you like to learn about?\n" + puts + puts build_solar_system.list_planets + print "\nPlanet:" + planet_choice = gets.chomp.downcase + + return planet_choice +end +def add_user_planet + puts "Let's add a planet! Enter the following information!" + puts "" + puts "What is the name of the planet?" + name = gets.chomp.downcase + puts "What color is the planet?" + color = gets.chomp.downcase + puts "What is the mass of the planet in kg?" + mass_kg = gets.chomp.to_i + puts "What is the distance from the sun in km?" + distance_from_sun_km = gets.chomp.to_i + puts "What is a fun fact about the planet?" + fun_fact = gets.chomp + new_planet = Planet.new(name, color, mass_kg, distance_from_sun_km, fun_fact) + + return new_planet +end + +def main + + solar_system = build_solar_system + + option_list_choice = user_choice + + while option_list_choice != "exit" + + case option_list_choice + when "list planets" + puts solar_system.list_planets + when "planet details" + user_planet = planet_details + found_planet = solar_system.find_planet_by_name(user_planet) + if found_planet + p found_planet.summary + else + puts " \"#{user_planet}\" could not be found." + end + when "add planet" + new_planet = add_user_planet + solar_system.add_planet(new_planet) + puts "Great, #{new_planet.name} has been added to the solar system!" + puts solar_system.list_planets + else + puts "The planet #{new_planet} is not on the list." + option_list_choice = user_choice + main + end + exit + end + return puts "\nThanks for stopping by!" +end + +main diff --git a/lib/solar_system.rb b/lib/solar_system.rb index 43083fca..d7c9a081 100644 --- a/lib/solar_system.rb +++ b/lib/solar_system.rb @@ -29,4 +29,5 @@ def find_planet_by_name(planet_name) return planet_found end -end \ No newline at end of file +end +