From c7db9e942a3b89796563fa70178325b055d2eb5c Mon Sep 17 00:00:00 2001 From: K <774162+kaseea@users.noreply.github.com> Date: Mon, 25 Feb 2019 13:55:33 -0800 Subject: [PATCH 1/6] wave 1 step one and two --- planet.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 planet.rb diff --git a/planet.rb b/planet.rb new file mode 100644 index 00000000..e7eae564 --- /dev/null +++ b/planet.rb @@ -0,0 +1,24 @@ +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 +end + +# Load Planet into pry: +# $ pry -r ./planet.rb +earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") + +puts earth.name +# => Earth +puts earth.fun_fact +# => Only planet known to support life + +earth.color = "pink" +# => NoMethodError: undefined method `color=' for # +# => Did you mean? color From 825352e447e56146e0499115b61188b50859c213 Mon Sep 17 00:00:00 2001 From: K <774162+kaseea@users.noreply.github.com> Date: Mon, 25 Feb 2019 14:05:32 -0800 Subject: [PATCH 2/6] wave 1 complete, optional exercises later --- main.rb | 10 ++++++++++ planet.rb | 17 ++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) create mode 100644 main.rb diff --git a/main.rb b/main.rb new file mode 100644 index 00000000..5266679a --- /dev/null +++ b/main.rb @@ -0,0 +1,10 @@ +require_relative "planet" + +def main + earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") + venus = Planet.new("Venus", "green", 6.972e24, 2.496e8, "moody") + puts venus.summary + puts earth.summary +end + +main diff --git a/planet.rb b/planet.rb index e7eae564..92e745eb 100644 --- a/planet.rb +++ b/planet.rb @@ -8,17 +8,8 @@ def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact) @distance_from_sun_km = distance_from_sun_km @fun_fact = fun_fact end -end - -# Load Planet into pry: -# $ pry -r ./planet.rb -earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") - -puts earth.name -# => Earth -puts earth.fun_fact -# => Only planet known to support life -earth.color = "pink" -# => NoMethodError: undefined method `color=' for # -# => Did you mean? color + def summary + return "#{self.name}: is #{self.color}, weighs #{self.mass_kg}, is #{self.distance_from_sun_km} km from the sun and #{self.fun_fact}" + end +end From a0de29c616b6b0a80035b1a5cafc49117b1b070f Mon Sep 17 00:00:00 2001 From: K <774162+kaseea@users.noreply.github.com> Date: Mon, 25 Feb 2019 15:02:24 -0800 Subject: [PATCH 3/6] added a solar_system class --- main.rb | 19 +++++++++++++++++-- planet.rb | 2 +- solar_system.rb | 20 ++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 solar_system.rb diff --git a/main.rb b/main.rb index 5266679a..e79c2f70 100644 --- a/main.rb +++ b/main.rb @@ -1,10 +1,25 @@ require_relative "planet" +require_relative "solar_system" def main + # solar_system = SolarSystem.new("Sol") + # earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") + # solar_system.add_planet(earth) + # venus = Planet.new("Venus", "green", 6.972e24, 2.496e8, "moody") + # solar_system.add_planet(venus) + # puts venus.summary + # puts earth.summary + # puts solar_system.list_planets + + solar_system = SolarSystem.new("Sol") + earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") + solar_system.add_planet(earth) venus = Planet.new("Venus", "green", 6.972e24, 2.496e8, "moody") - puts venus.summary - puts earth.summary + solar_system.add_planet(venus) + + list = solar_system.list_planets + puts list end main diff --git a/planet.rb b/planet.rb index 92e745eb..64f7db51 100644 --- a/planet.rb +++ b/planet.rb @@ -10,6 +10,6 @@ def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact) end def summary - return "#{self.name}: is #{self.color}, weighs #{self.mass_kg}, is #{self.distance_from_sun_km} km from the sun and #{self.fun_fact}" + return "#{name}: is #{color}, weighs #{mass_kg}, is #{distance_from_sun_km} km from the sun and #{fun_fact}" end end diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..ea39e55c --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,20 @@ +class SolarSystem + attr_reader :star_name, :planets + + def initialize(star_name) + @star_name = star_name + @planets = [] + end + + def add_planet(planet) + @planets << planet + end + + def list_planets() + planet_list = "Planets orbiting #{star_name}: \n" + @planets.each_with_index do |planet, i| + planet_list << "#{i + 1}: #{planet.name} \n" + end + return planet_list + end +end From facd62562144fa9cd7fb2c58a533cd90a9118b28 Mon Sep 17 00:00:00 2001 From: K <774162+kaseea@users.noreply.github.com> Date: Tue, 26 Feb 2019 07:38:02 -0800 Subject: [PATCH 4/6] required sections through wav 2 --- main.rb | 10 ++++++++++ solar_system.rb | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/main.rb b/main.rb index e79c2f70..53269129 100644 --- a/main.rb +++ b/main.rb @@ -17,9 +17,19 @@ def main solar_system.add_planet(earth) venus = Planet.new("Venus", "green", 6.972e24, 2.496e8, "moody") solar_system.add_planet(venus) + mars = Planet.new("mars", "red", 4.972e24, 0.496e8, "agro") + solar_system.add_planet(mars) list = solar_system.list_planets puts list + + found_planet = solar_system.find_planet_by_name("Earth") + + # found_planet is an instance of class Planet + puts found_planet + # => # + + puts found_planet.summary end main diff --git a/solar_system.rb b/solar_system.rb index ea39e55c..4d4e9d7f 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -17,4 +17,14 @@ def list_planets() end return planet_list end + + def find_planet_by_name(name) + #because the puts statement is in main, I can't have multipe answer can I + found = @planets.each { |sol| sol.name.casecmp(name) == 0 } + if found.length == 0 + return "#{name} is not in our solar system" + else + return found[0] + end + end end From d8ac9e8f7cc1b6c395c7d0859afaa52de7a6ef00 Mon Sep 17 00:00:00 2001 From: K <774162+kaseea@users.noreply.github.com> Date: Wed, 27 Feb 2019 07:46:44 -0800 Subject: [PATCH 5/6] wave 3 --- main.rb | 66 ++++++++++++++++++++++++++++++++----------------- solar_system.rb | 14 ++++------- 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/main.rb b/main.rb index 53269129..85fcc7bd 100644 --- a/main.rb +++ b/main.rb @@ -2,34 +2,54 @@ require_relative "solar_system" def main - # solar_system = SolarSystem.new("Sol") - # earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") - # solar_system.add_planet(earth) - # venus = Planet.new("Venus", "green", 6.972e24, 2.496e8, "moody") - # solar_system.add_planet(venus) - # puts venus.summary - # puts earth.summary - # puts solar_system.list_planets - solar_system = SolarSystem.new("Sol") - earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") solar_system.add_planet(earth) venus = Planet.new("Venus", "green", 6.972e24, 2.496e8, "moody") solar_system.add_planet(venus) - mars = Planet.new("mars", "red", 4.972e24, 0.496e8, "agro") - solar_system.add_planet(mars) - - list = solar_system.list_planets - puts list - - found_planet = solar_system.find_planet_by_name("Earth") - - # found_planet is an instance of class Planet - puts found_planet - # => # - - puts found_planet.summary + astra = Planet.new("Astra", "silver", 5, 23, "Marvel Universe planet") + solar_system.add_planet(astra) + ego = Planet.new("Ego", "green", 124234, 325623, "Marvel bioverse") + solar_system.add_planet(ego) + namek = Planet.new("Namek", "blue-green", 35435472, 23513541, "Dragon Ball world with lots of water and grass") + solar_system.add_planet(namek) + + def wanna_add_planet() + puts "please add a planet: what is the planets name?" + name = gets.chomp + puts "and color?" + color = gets.chomp + puts "and mass?" + mass_kg = gets.chomp + puts "and distance from the sun?" + distance_from_sun_km = gets.chomp + puts "and please share a fun fact" + fun_fact = gets.chomp + planet = Planet.new(name, color, mass_kg, distance_from_sun_km, fun_fact) + return planet + end + + loop do + puts "do you want to" + puts "1. list planets" + puts "2. planet details" + puts "3. add planet" + puts "4. exit" + answer = gets.chomp + if answer.to_i == 1 || answer == "list planets" + list = solar_system.list_planets + puts list + elsif answer.to_i == 2 || answer == "planet details" + puts "what planet do you want more info on" + planet = gets.chomp + found_planet = solar_system.find_planet_by_name(planet) + puts found_planet.summary + elsif answer.to_i == 3 || answer == "add planet" + solar_system.add_planet(wanna_add_planet()) + else + break + end + end end main diff --git a/solar_system.rb b/solar_system.rb index 4d4e9d7f..310cf85c 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -18,13 +18,9 @@ def list_planets() return planet_list end - def find_planet_by_name(name) - #because the puts statement is in main, I can't have multipe answer can I - found = @planets.each { |sol| sol.name.casecmp(name) == 0 } - if found.length == 0 - return "#{name} is not in our solar system" - else - return found[0] - end - end + def find_planet_by_name(planet_name) I + found = @planets.find { |planet| + planet.name.upcase == planet_name.upcase + } + return found end end From b690605f7079d4687585864f0b7d793396739862 Mon Sep 17 00:00:00 2001 From: K <774162+kaseea@users.noreply.github.com> Date: Wed, 27 Feb 2019 10:19:59 -0800 Subject: [PATCH 6/6] fixes a keystroke error while saving that I didn't notice --- solar_system.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/solar_system.rb b/solar_system.rb index 310cf85c..7baf2b38 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -18,9 +18,10 @@ def list_planets() return planet_list end - def find_planet_by_name(planet_name) I + def find_planet_by_name(planet_name) found = @planets.find { |planet| - planet.name.upcase == planet_name.upcase - } - return found end + planet.name.upcase == planet_name.upcase + } + return found + end end