From 760ae1d7d9409b76fb2621b28b8540430d5a9ebd Mon Sep 17 00:00:00 2001 From: mulhoo Date: Wed, 19 Feb 2020 21:00:43 -0800 Subject: [PATCH 1/7] Wave 0 commit --- main.rb | 16 ++++++++++++++++ planet.rb | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 main.rb create mode 100644 planet.rb diff --git a/main.rb b/main.rb new file mode 100644 index 00000000..3031d17a --- /dev/null +++ b/main.rb @@ -0,0 +1,16 @@ +require_relative 'planet' + +def main + tatooine = Planet.new("Tatooine", "brown", 20, 100, "Home to Luke Skywalker.") + endor = Planet.new("Endor", "green", 22, 200, "The small moon that orbits it has Ewoks.") + coruscant = Planet.new("Coruscant", "black", 19, 300, "Was considered the most politcally important world in the galaxy at one point." ) + bespin = Planet.new("Bespin", "sunset", 10, 400, "A gas giant whose cities float in the clouds.") + + puts tatooine.name + puts tatooine.color + + puts endor.name + puts endor.color +end + +main \ No newline at end of file diff --git a/planet.rb b/planet.rb new file mode 100644 index 00000000..ddb6ae82 --- /dev/null +++ b/planet.rb @@ -0,0 +1,16 @@ +class Planet + attr_accessor :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 + + +end + + + From ac7a2357c85485c7cc9648266ffc6572fe817800 Mon Sep 17 00:00:00 2001 From: mulhoo Date: Wed, 19 Feb 2020 21:18:40 -0800 Subject: [PATCH 2/7] Wave 1 completion --- main.rb | 14 +++++--------- planet.rb | 5 ++++- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/main.rb b/main.rb index 3031d17a..b7c0bd4f 100644 --- a/main.rb +++ b/main.rb @@ -1,16 +1,12 @@ require_relative 'planet' def main - tatooine = Planet.new("Tatooine", "brown", 20, 100, "Home to Luke Skywalker.") - endor = Planet.new("Endor", "green", 22, 200, "The small moon that orbits it has Ewoks.") - coruscant = Planet.new("Coruscant", "black", 19, 300, "Was considered the most politcally important world in the galaxy at one point." ) - bespin = Planet.new("Bespin", "sunset", 10, 400, "A gas giant whose cities float in the clouds.") + tatooine = Planet.new("Tatooine", "brown", 20, 100, "Home to Luke Skywalker") + endor = Planet.new("Endor", "green", 22, 200, "The small moon that orbits it has Ewoks") + coruscant = Planet.new("Coruscant", "black", 19, 300, "Was considered the most politcally important world in the galaxy at one point" ) + bespin = Planet.new("Bespin", "sunset", 10, 400, "A gas giant whose cities float in the clouds") - puts tatooine.name - puts tatooine.color - - puts endor.name - puts endor.color + puts endor.summary end main \ No newline at end of file diff --git a/planet.rb b/planet.rb index ddb6ae82..35df71cf 100644 --- a/planet.rb +++ b/planet.rb @@ -9,7 +9,10 @@ def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact) @fun_fact = fun_fact end - + def summary + return "This is #{@name}. #{@name} is #{@color}, weighs #{@mass_kg}kg, and is #{@distance_from_sun_km}km from the sun. #{@fun_fact}." + end + end From f7cfa343bf6506b7a355c65fcea8dd0e5fafa984 Mon Sep 17 00:00:00 2001 From: mulhoo Date: Wed, 19 Feb 2020 21:19:22 -0800 Subject: [PATCH 3/7] Adding solar_system.rb --- solar_system.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 solar_system.rb diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..e6aa6f72 --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,5 @@ +class SolarSystem + + + +end From 0fc769d450a9a2b66da015bfcf3259c8609d85c7 Mon Sep 17 00:00:00 2001 From: mulhoo Date: Thu, 20 Feb 2020 01:34:38 -0800 Subject: [PATCH 4/7] End Wave 2, Begin Wave 3 --- main.rb | 34 +++++++++++++++++++++++++++++++++- solar_system.rb | 25 ++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/main.rb b/main.rb index b7c0bd4f..f0216721 100644 --- a/main.rb +++ b/main.rb @@ -1,4 +1,5 @@ require_relative 'planet' +require_relative 'solar_system' def main tatooine = Planet.new("Tatooine", "brown", 20, 100, "Home to Luke Skywalker") @@ -6,7 +7,38 @@ def main coruscant = Planet.new("Coruscant", "black", 19, 300, "Was considered the most politcally important world in the galaxy at one point" ) bespin = Planet.new("Bespin", "sunset", 10, 400, "A gas giant whose cities float in the clouds") - puts endor.summary + solar_system = SolarSystem.new('Vēzos') + solar_system.add_planet(tatooine) + solar_system.add_planet(endor) + solar_system.add_planet(coruscant) + solar_system.add_planet(bespin) + + user_choice = nil + until user_choice = "exit" + puts "You can see the current list of planets in your solar system ('LIST PLANETS'), " + print "or see details on a specific planet ('DETAILS')." + puts "To add another planet, please type 'ADD PLANET'." + puts "To exit the program, please type 'EXIT'." + user_choice = gets.chomp.upcase + + if user_choice = "LIST PLANETS" + list = solar_system.list_planets + puts list + + elsif user_choice = "DETAILS" + puts "Which planet would you like to know more about?" + user_planet_search = gets.chomp.downcase + solar_system.find_planet_by_name(user_planet_search) + + elsif user_choice = "ADD PLANET" + + + elsif user_choice = "EXIT" + puts "#{solar_system.star_name} is supernova-ing your system." + + end + + end main \ No newline at end of file diff --git a/solar_system.rb b/solar_system.rb index e6aa6f72..09138b6c 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -1,5 +1,28 @@ class SolarSystem - + attr_reader :planets, :star_name + def initialize(star_name) + @star_name = star_name + @planets = [] + end + + def add_planet(planet) + @planets << planet + return planets + end + + + def list_planets + puts "Planets Orbiting #{star_name}: " + return @planets.each_with_index do |planet, i| + puts "##{i+1}. #{planet.name}" + end + end + + def find_planet_by_name(planet) + if @planets.include?(planet) == true + return planet + end + end end From 8f6f8ed221edfcc8792e9452d00829b40b3607cc Mon Sep 17 00:00:00 2001 From: mulhoo Date: Thu, 20 Feb 2020 02:25:21 -0800 Subject: [PATCH 5/7] Updated to fulfill Wave 3 --- main.rb | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/main.rb b/main.rb index f0216721..84fb1f12 100644 --- a/main.rb +++ b/main.rb @@ -13,31 +13,64 @@ def main solar_system.add_planet(coruscant) solar_system.add_planet(bespin) + def add_planet(new_planet) + name = new_planet + + puts "I need some more information about this new planet of yours:" + puts "1. What color is it? " + color = gets.chomp + + puts "2. What is the mass of the planet, in kg?" + mass_kg = gets.chomp.to_i + + puts "3. How far is this planet from the sun, in km?" + distance_from_sun_km = gets.chomp.to_i + + puts "4. Last question, do you any have any fun facts about this planet? (Y/N)" + fun_fact = gets.chomp + if fun_fact == "Y" + puts "Okay! Give me a fun fact about #{new_planet_name}: " + fun_fact = gets.chomp + elsif fun_fact != "Y" + fun_fact = "There are no fun facts about this planet" + end + + new_planet = Planet.new(name, color, mass_kg, distance_from_sun_km, fun_fact) + + return new_planet + end + user_choice = nil - until user_choice = "exit" - puts "You can see the current list of planets in your solar system ('LIST PLANETS'), " - print "or see details on a specific planet ('DETAILS')." + + until user_choice == "EXIT" + + puts "\nTo see the current list of planets in your solar system, please type 'LIST PLANETS'." + puts "To see details on a specific planet, please type 'DETAILS'." puts "To add another planet, please type 'ADD PLANET'." puts "To exit the program, please type 'EXIT'." user_choice = gets.chomp.upcase + puts "\n" - if user_choice = "LIST PLANETS" + if user_choice == "LIST PLANETS" list = solar_system.list_planets puts list - elsif user_choice = "DETAILS" + elsif user_choice == "DETAILS" puts "Which planet would you like to know more about?" user_planet_search = gets.chomp.downcase solar_system.find_planet_by_name(user_planet_search) - elsif user_choice = "ADD PLANET" + elsif user_choice == "ADD PLANET" + puts "What would you like to call your new planet?" + new_planet_name = gets.chomp.capitalize + nuevo_planeta = add_planet(new_planet_name) + solar_system.add_planet(nuevo_planeta) - - elsif user_choice = "EXIT" - puts "#{solar_system.star_name} is supernova-ing your system." + elsif user_choice == "EXIT" + puts "#{solar_system.star_name} has gone supernova and destroyed your system. Goodbye." end - + end end From a0925c3a48768052691bc87c0156ed5b2b0fd3d3 Mon Sep 17 00:00:00 2001 From: mulhoo Date: Thu, 20 Feb 2020 08:45:20 -0800 Subject: [PATCH 6/7] Wave 3 final --- main.rb | 3 ++- solar_system.rb | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/main.rb b/main.rb index 84fb1f12..36d7395a 100644 --- a/main.rb +++ b/main.rb @@ -57,8 +57,9 @@ def add_planet(new_planet) elsif user_choice == "DETAILS" puts "Which planet would you like to know more about?" + puts solar_system.list_planets user_planet_search = gets.chomp.downcase - solar_system.find_planet_by_name(user_planet_search) + puts solar_system.find_planet_by_name(user_planet_search).summary elsif user_choice == "ADD PLANET" puts "What would you like to call your new planet?" diff --git a/solar_system.rb b/solar_system.rb index 09138b6c..b93becdb 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -1,3 +1,5 @@ +require 'pry' + class SolarSystem attr_reader :planets, :star_name @@ -8,7 +10,7 @@ def initialize(star_name) def add_planet(planet) @planets << planet - return planets + return @planets end @@ -20,8 +22,15 @@ def list_planets end def find_planet_by_name(planet) - if @planets.include?(planet) == true - return planet + # if @planets.include?(planet) + # binding.pry + # return planet + @planets.each do |body| + body.name.downcase! + # binding.pry + if body.name == planet + return body + end end end From 5865b61f61fe74fb71d683b38187aca3541a804a Mon Sep 17 00:00:00 2001 From: mulhoo Date: Thu, 20 Feb 2020 08:49:21 -0800 Subject: [PATCH 7/7] remove pry --- solar_system.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/solar_system.rb b/solar_system.rb index b93becdb..198d2310 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -1,5 +1,3 @@ -require 'pry' - class SolarSystem attr_reader :planets, :star_name @@ -22,12 +20,8 @@ def list_planets end def find_planet_by_name(planet) - # if @planets.include?(planet) - # binding.pry - # return planet @planets.each do |body| body.name.downcase! - # binding.pry if body.name == planet return body end