From fd8ccd72059bbb18c691a7cafaf765d9167b78f8 Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 25 Feb 2019 13:39:38 -0800 Subject: [PATCH 01/24] created planet.rb --- planet.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 planet.rb diff --git a/planet.rb b/planet.rb new file mode 100644 index 00000000..ed39a4a8 --- /dev/null +++ b/planet.rb @@ -0,0 +1,9 @@ +class Planet + def initialize(name, color, mass_kg, distance_from_the_sun_km, fun_fact) + @name = name + @color = color + @mass_kg = mass_kg + @distance_from_the_sun_km = distance_from_the_sun_km + @fun_fact = fun_fact + end +end From d9f05a2f83ff20097f999faa62039816f6cc2908 Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 25 Feb 2019 13:48:03 -0800 Subject: [PATCH 02/24] added main.rb --- main.rb | 6 ++++++ planet.rb | 13 +++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 main.rb diff --git a/main.rb b/main.rb new file mode 100644 index 00000000..3a065418 --- /dev/null +++ b/main.rb @@ -0,0 +1,6 @@ +require_relative "planet" + +def main +end + +main diff --git a/planet.rb b/planet.rb index ed39a4a8..7d92dfaa 100644 --- a/planet.rb +++ b/planet.rb @@ -6,4 +6,17 @@ def initialize(name, color, mass_kg, distance_from_the_sun_km, fun_fact) @distance_from_the_sun_km = distance_from_the_sun_km @fun_fact = fun_fact end + + attr_reader :name, :color, :mass_kg, :distance_from_the_sun_km, :fun_fact end + +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 3afffc51ddbf67a92bc8e1aa985837a275f78567 Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 25 Feb 2019 13:53:38 -0800 Subject: [PATCH 03/24] added summary instance method --- planet.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/planet.rb b/planet.rb index 7d92dfaa..83c33069 100644 --- a/planet.rb +++ b/planet.rb @@ -8,6 +8,14 @@ def initialize(name, color, mass_kg, distance_from_the_sun_km, fun_fact) end attr_reader :name, :color, :mass_kg, :distance_from_the_sun_km, :fun_fact + + def summary + return "Planet name: #{@name}. \n + Color: #{@color} \n + Weight: #{@mass_kg} \n + Distance from sun: #{distance_from_the_sun_km} \n + Fun Fact: #{fun_fact}" + end end earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") From f0e2376e6540098df60d2004750a2d16f87fa11b Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 25 Feb 2019 13:54:09 -0800 Subject: [PATCH 04/24] fixed mars distance formatting --- main.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.rb b/main.rb index 3a065418..12bac4bf 100644 --- a/main.rb +++ b/main.rb @@ -1,6 +1,9 @@ require_relative "planet" def main + earth = Planet.new("Earth", "blue-green", 5.972e24, 1.49638, "houses these things called humans") + + mars = Planet.new("Mars", "scary-red", 4.930e24, 0.43523, "cool fact about mars") end main From 8c0dbeca98196fd164985aaba1a142f0b1c4289e Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 25 Feb 2019 14:02:19 -0800 Subject: [PATCH 05/24] fixed summary output formatting --- planet.rb | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/planet.rb b/planet.rb index 83c33069..8ea85278 100644 --- a/planet.rb +++ b/planet.rb @@ -10,21 +10,6 @@ def initialize(name, color, mass_kg, distance_from_the_sun_km, fun_fact) attr_reader :name, :color, :mass_kg, :distance_from_the_sun_km, :fun_fact def summary - return "Planet name: #{@name}. \n - Color: #{@color} \n - Weight: #{@mass_kg} \n - Distance from sun: #{distance_from_the_sun_km} \n - Fun Fact: #{fun_fact}" + return "Planet name: #{@name}", "Color: #{@color}", "Weight: #{@mass_kg}", "Distance from sun: #{@distance_from_the_sun_km}", "Fun Fact: #{@fun_fact}" end end - -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 2ff988f69bc7ece6982994c2079801ae52900f12 Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 25 Feb 2019 14:07:41 -0800 Subject: [PATCH 06/24] created solar_system file and added SolarSystem class. --- solar_system.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 solar_system.rb diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..c1ee5106 --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,8 @@ +class SolarSystem + def initialize(star_name) + @star_name = star_name + @planets = [] + end + + attr_reader :star_name, :planets +end From 8fc6f83ee43fd4ce4c3f8d56d660672f6936bd6f Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 25 Feb 2019 14:22:44 -0800 Subject: [PATCH 07/24] added list_planets method --- solar_system.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/solar_system.rb b/solar_system.rb index c1ee5106..0a44e2ba 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -5,4 +5,15 @@ def initialize(star_name) end attr_reader :star_name, :planets + + def add_planet(planet_instance) + @planets.push(planet_instance) + end + + def list_planets + return "Planets orbiting #{@star_name}", + @planets.each do |planet| + "#{planet}" + end + end end From 522828c561a4da5e42f5e8ab620bddce4b05e9f0 Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 25 Feb 2019 14:34:03 -0800 Subject: [PATCH 08/24] fixed formatting for list_planets --- solar_system.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/solar_system.rb b/solar_system.rb index 0a44e2ba..f9aebfb7 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -10,10 +10,10 @@ def add_planet(planet_instance) @planets.push(planet_instance) end - def list_planets + def list_planets #need to fix formatting with returns return "Planets orbiting #{@star_name}", - @planets.each do |planet| - "#{planet}" + @planets.map!.each_with_index do |planet, index| + "#{index + 1}. #{planet}" end end end From 122b6ebc9ed495bd9f4e2336c050c1a4072069bc Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 25 Feb 2019 14:36:32 -0800 Subject: [PATCH 09/24] fixed formatting list_planets --- solar_system.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solar_system.rb b/solar_system.rb index f9aebfb7..6287ff61 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -10,7 +10,7 @@ def add_planet(planet_instance) @planets.push(planet_instance) end - def list_planets #need to fix formatting with returns + def list_planets return "Planets orbiting #{@star_name}", @planets.map!.each_with_index do |planet, index| "#{index + 1}. #{planet}" From 6b7742a991191688287a1c05843db23a6cd9166b Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 25 Feb 2019 15:14:21 -0800 Subject: [PATCH 10/24] fixed planets_list --- main.rb | 9 ++++++++- solar_system.rb | 12 ++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/main.rb b/main.rb index 12bac4bf..22eaa758 100644 --- a/main.rb +++ b/main.rb @@ -1,9 +1,16 @@ require_relative "planet" +require_relative "solar_system" def main earth = Planet.new("Earth", "blue-green", 5.972e24, 1.49638, "houses these things called humans") - mars = Planet.new("Mars", "scary-red", 4.930e24, 0.43523, "cool fact about mars") + + solar_system = SolarSystem.new("Brittny") + solar_system.add_planet(earth) + solar_system.add_planet(mars) + list = solar_system.list_planets + puts list end main +# puts main.summary diff --git a/solar_system.rb b/solar_system.rb index 6287ff61..e406ece7 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -11,9 +11,13 @@ def add_planet(planet_instance) end def list_planets - return "Planets orbiting #{@star_name}", - @planets.map!.each_with_index do |planet, index| - "#{index + 1}. #{planet}" - end + output = "Planets orbiting #{@star_name}\n" + tracker = 1 + @planets.each do |planet| + output += "#{tracker}" + ". " + planet.name + "\n" + tracker += 1 + end + + return output end end From 0313bdcc5fc23f35187f0dfd7341ce1de4573061 Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 25 Feb 2019 16:03:46 -0800 Subject: [PATCH 11/24] added find_planet_by_name --- solar_system.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/solar_system.rb b/solar_system.rb index e406ece7..545032b8 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -17,7 +17,17 @@ def list_planets output += "#{tracker}" + ". " + planet.name + "\n" tracker += 1 end - return output end + + def find_planet_by_name(planet_name) + planet_name = planet_name.downcase.capitalize + @planets.each do |planet| + if planet.name == planet_name + return planet + else + raise ArgumentError, "You must input an existing planet name." + end + end + end end From eef819fdec45dd9fa6d2472e1b5fd2b00c7dfd39 Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 25 Feb 2019 16:04:21 -0800 Subject: [PATCH 12/24] fixed formatting for summary --- planet.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/planet.rb b/planet.rb index 8ea85278..49a4eaf1 100644 --- a/planet.rb +++ b/planet.rb @@ -10,6 +10,13 @@ def initialize(name, color, mass_kg, distance_from_the_sun_km, fun_fact) attr_reader :name, :color, :mass_kg, :distance_from_the_sun_km, :fun_fact def summary - return "Planet name: #{@name}", "Color: #{@color}", "Weight: #{@mass_kg}", "Distance from sun: #{@distance_from_the_sun_km}", "Fun Fact: #{@fun_fact}" + summary = "Planet name: #{@name} \nColor: #{@color} \nWeight: #{@mass_kg} \nDistance from sun: #{@distance_from_the_sun_km} \nFun Fact: #{@fun_fact}" + + return summary end + + # add if we want to return puts "a #{planet}" as summary + # def to_s + # return summary + # end end From 09f52e47acbc5d506924245ad558a8f8ebcda450 Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 25 Feb 2019 16:11:09 -0800 Subject: [PATCH 13/24] added control loop and new planets in main --- main.rb | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/main.rb b/main.rb index 22eaa758..12c398a1 100644 --- a/main.rb +++ b/main.rb @@ -2,15 +2,47 @@ require_relative "solar_system" def main - earth = Planet.new("Earth", "blue-green", 5.972e24, 1.49638, "houses these things called humans") - mars = Planet.new("Mars", "scary-red", 4.930e24, 0.43523, "cool fact about mars") - - solar_system = SolarSystem.new("Brittny") - solar_system.add_planet(earth) - solar_system.add_planet(mars) - list = solar_system.list_planets - puts list + #initialize solar system and planets + food_way = SolarSystem.new("Pad Thai Star") + burger = Planet.new("Burger", "brown", 23423, 234, "Inhabitants of burger really like to eat meat.") + salad = Planet.new("Salad", "green and others depending on time", 236, 235, "The planet Salad changes colors depending on the season.") + pho = Planet.new("Pho", "white and brown", 75, 234854, "The planet Pho always smells delicious.") + + #add to solar system + food_way.add_planet(burger) + food_way.add_planet(salad) + food_way.add_planet(pho) + + # control loop for program next steps + next_step = "" + until next_step == "exit" + puts "What would you like to do next? Options - 'list planets', or 'exit'" + next_step = gets.chomp.downcase + if next_step == "list planets" + list = food_way.list_planets + puts list + end + end end +### OLD CODE ##### +# earth = Planet.new("Earth", "blue-green", 5.972e24, 1.49638, "houses these things called humans") +# mars = Planet.new("Mars", "scary-red", 4.930e24, 0.43523, "a day in Mars lasts 24 hours and 39 minutes long") + +# puts earth +# puts mars.summary + +# # checking for accurate formatting and list of planets +# solar_system = SolarSystem.new("Brittny") +# solar_system.add_planet(earth) +# solar_system.add_planet(mars) +# list = solar_system.list_planets +# puts list + +# # checking for accurate found_planet +# found_planet = solar_system.find_planet_by_name("earth") +# puts found_planet +# puts found_planet.summary + main # puts main.summary From 553b8195c25634e12992bae6cf32d426e6086a71 Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 25 Feb 2019 16:16:30 -0800 Subject: [PATCH 14/24] added planet details option --- main.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.rb b/main.rb index 12c398a1..b6f675b6 100644 --- a/main.rb +++ b/main.rb @@ -16,11 +16,16 @@ def main # control loop for program next steps next_step = "" until next_step == "exit" - puts "What would you like to do next? Options - 'list planets', or 'exit'" + puts "What would you like to do next? Options - 'list planets', 'planet details', or 'exit'" next_step = gets.chomp.downcase if next_step == "list planets" list = food_way.list_planets puts list + elsif next_step == "planet details" + puts "Which planet would you like to learn more about?" + user_planet = gets.chomp + found_planet = food_way.find_planet_by_name(user_planet) + puts found_planet.summary end end end From 390d8089ea00085d8307be2255ea61609e75a068 Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 25 Feb 2019 16:28:13 -0800 Subject: [PATCH 15/24] added add planet function --- main.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/main.rb b/main.rb index b6f675b6..2ae4115d 100644 --- a/main.rb +++ b/main.rb @@ -16,7 +16,7 @@ def main # control loop for program next steps next_step = "" until next_step == "exit" - puts "What would you like to do next? Options - 'list planets', 'planet details', or 'exit'" + puts "What would you like to do next? Options - 'list planets', 'planet details', 'add planet', or 'exit'" next_step = gets.chomp.downcase if next_step == "list planets" list = food_way.list_planets @@ -26,6 +26,19 @@ def main user_planet = gets.chomp found_planet = food_way.find_planet_by_name(user_planet) puts found_planet.summary + elsif next_step == "add planet" + puts "What planet would you like to add?" + new_planet = gets.chomp.capitalize + puts "What color is it?" + planet_color = gets.chomp + puts "How heavy is it - in kilograms?" + planet_mass = gets.chomp.to_i + puts "How far from the sun is it - in kilometers?" + planet_distance = gets.chomp.to_i + puts "Enter a fun fact!" + planet_fun = gets.chomp + adding_planet = Planet.new(new_planet, planet_color, planet_mass, planet_distance, planet_fun) + food_way.add_planet(adding_planet) end end end From 9b7c3576668b72ae50fb3271545878db9d1825fc Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 25 Feb 2019 16:34:30 -0800 Subject: [PATCH 16/24] error handling for non-existing planets --- main.rb | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/main.rb b/main.rb index 2ae4115d..7189c45c 100644 --- a/main.rb +++ b/main.rb @@ -25,7 +25,11 @@ def main puts "Which planet would you like to learn more about?" user_planet = gets.chomp found_planet = food_way.find_planet_by_name(user_planet) - puts found_planet.summary + if found_planet == nil + puts "Sorry, that planet does not exist in the Food Way Solar System. Check your spelling or try a different planet." + else + puts found_planet.summary + end elsif next_step == "add planet" puts "What planet would you like to add?" new_planet = gets.chomp.capitalize @@ -43,24 +47,4 @@ def main end end -### OLD CODE ##### -# earth = Planet.new("Earth", "blue-green", 5.972e24, 1.49638, "houses these things called humans") -# mars = Planet.new("Mars", "scary-red", 4.930e24, 0.43523, "a day in Mars lasts 24 hours and 39 minutes long") - -# puts earth -# puts mars.summary - -# # checking for accurate formatting and list of planets -# solar_system = SolarSystem.new("Brittny") -# solar_system.add_planet(earth) -# solar_system.add_planet(mars) -# list = solar_system.list_planets -# puts list - -# # checking for accurate found_planet -# found_planet = solar_system.find_planet_by_name("earth") -# puts found_planet -# puts found_planet.summary - main -# puts main.summary From ecf1bedf78051857d00bde5d0fcf865db9da1030 Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 25 Feb 2019 16:57:05 -0800 Subject: [PATCH 17/24] fixed controll error for find planet --- solar_system.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/solar_system.rb b/solar_system.rb index 545032b8..7092f3c6 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -22,12 +22,15 @@ def list_planets def find_planet_by_name(planet_name) planet_name = planet_name.downcase.capitalize + # puts "This is user input: #{planet_name}" @planets.each do |planet| + # puts "This is planet.name: #{planet.name}" if planet.name == planet_name return planet else - raise ArgumentError, "You must input an existing planet name." + object = planet end end + return nil end end From a681d906c4b9e0a4dd6ba207567b81ea4222d761 Mon Sep 17 00:00:00 2001 From: Angela Date: Tue, 26 Feb 2019 12:40:58 -0800 Subject: [PATCH 18/24] added welcome message --- main.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.rb b/main.rb index 7189c45c..98c2d3b3 100644 --- a/main.rb +++ b/main.rb @@ -1,6 +1,13 @@ require_relative "planet" require_relative "solar_system" +#welcome message +puts "Welcome to our Solar System! You can do the following with this program." +puts "1. List Planets" +puts "2. Planet Details" +puts "3. Add Planet" +puts "4. Exit" + def main #initialize solar system and planets food_way = SolarSystem.new("Pad Thai Star") @@ -16,7 +23,7 @@ def main # control loop for program next steps next_step = "" until next_step == "exit" - puts "What would you like to do next? Options - 'list planets', 'planet details', 'add planet', or 'exit'" + puts "What would you like to do? Options - 'list planets', 'planet details', 'add planet', or 'exit'" next_step = gets.chomp.downcase if next_step == "list planets" list = food_way.list_planets @@ -43,6 +50,8 @@ def main planet_fun = gets.chomp adding_planet = Planet.new(new_planet, planet_color, planet_mass, planet_distance, planet_fun) food_way.add_planet(adding_planet) + else + puts "This is not an option. Try again." end end end From 17a150b755936994f4b4cb9089324e5d8cc36f1e Mon Sep 17 00:00:00 2001 From: Angela Date: Tue, 26 Feb 2019 12:52:33 -0800 Subject: [PATCH 19/24] error control for planet mass and distance --- planet.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/planet.rb b/planet.rb index 49a4eaf1..d06d06ea 100644 --- a/planet.rb +++ b/planet.rb @@ -2,8 +2,17 @@ class Planet def initialize(name, color, mass_kg, distance_from_the_sun_km, fun_fact) @name = name @color = color - @mass_kg = mass_kg - @distance_from_the_sun_km = distance_from_the_sun_km + if mass_kg.class != Integer || mass_kg < 0 + @mass_kg = 0 + else + @mass_kg = mass_kg + end + # @distance_from_the_sun_km = distance_from_the_sun_km + if distance_from_the_sun_km != Integer || distance_from_the_sun_km < 0 + @distance_from_the_sun_km = 0 + else + @distance_from_the_sun_km = distance_from_the_sun_km + end @fun_fact = fun_fact end From 6a2529e2c9fdb143f657a90831f628a2f1e553ec Mon Sep 17 00:00:00 2001 From: Angela Date: Tue, 26 Feb 2019 12:52:57 -0800 Subject: [PATCH 20/24] tested planet.rb weight and distance values --- main.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.rb b/main.rb index 98c2d3b3..6d6e2a29 100644 --- a/main.rb +++ b/main.rb @@ -11,7 +11,7 @@ def main #initialize solar system and planets food_way = SolarSystem.new("Pad Thai Star") - burger = Planet.new("Burger", "brown", 23423, 234, "Inhabitants of burger really like to eat meat.") + burger = Planet.new("Burger", "brown", 3453, 234, "Inhabitants of burger really like to eat meat.") salad = Planet.new("Salad", "green and others depending on time", 236, 235, "The planet Salad changes colors depending on the season.") pho = Planet.new("Pho", "white and brown", 75, 234854, "The planet Pho always smells delicious.") From e4c23be7edb8e03bf8dbad142f5a4bf1a26f05c9 Mon Sep 17 00:00:00 2001 From: Angela Date: Tue, 26 Feb 2019 12:53:33 -0800 Subject: [PATCH 21/24] deleted unnecessary comments --- solar_system.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/solar_system.rb b/solar_system.rb index 7092f3c6..a023c4ab 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -12,19 +12,15 @@ def add_planet(planet_instance) def list_planets output = "Planets orbiting #{@star_name}\n" - tracker = 1 - @planets.each do |planet| - output += "#{tracker}" + ". " + planet.name + "\n" - tracker += 1 + @planets.each_with_index do |planet, index| + output += "#{index + 1}" + ". " + planet.name + "\n" end return output end def find_planet_by_name(planet_name) planet_name = planet_name.downcase.capitalize - # puts "This is user input: #{planet_name}" @planets.each do |planet| - # puts "This is planet.name: #{planet.name}" if planet.name == planet_name return planet else From 6f53d5c45c80f0a00fa87967998fba1534086e4d Mon Sep 17 00:00:00 2001 From: Angela Date: Tue, 26 Feb 2019 13:32:14 -0800 Subject: [PATCH 22/24] deleted unnecessary comments --- planet.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/planet.rb b/planet.rb index d06d06ea..39ccc578 100644 --- a/planet.rb +++ b/planet.rb @@ -7,7 +7,6 @@ def initialize(name, color, mass_kg, distance_from_the_sun_km, fun_fact) else @mass_kg = mass_kg end - # @distance_from_the_sun_km = distance_from_the_sun_km if distance_from_the_sun_km != Integer || distance_from_the_sun_km < 0 @distance_from_the_sun_km = 0 else @@ -23,9 +22,4 @@ def summary return summary end - - # add if we want to return puts "a #{planet}" as summary - # def to_s - # return summary - # end end From 3cd1abc844415a4d6489d75559a82d96151de9f5 Mon Sep 17 00:00:00 2001 From: Angela Date: Tue, 26 Feb 2019 13:37:07 -0800 Subject: [PATCH 23/24] fixed control loop for weird next steps input --- main.rb | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/main.rb b/main.rb index 6d6e2a29..cebc3d76 100644 --- a/main.rb +++ b/main.rb @@ -1,12 +1,13 @@ require_relative "planet" require_relative "solar_system" +require "colorize" -#welcome message -puts "Welcome to our Solar System! You can do the following with this program." -puts "1. List Planets" -puts "2. Planet Details" -puts "3. Add Planet" -puts "4. Exit" +#welcome message" +options = ["List Planets", "Planet Details", "Add Planet", "Exit"] +puts "Welcome to our Solar System! You can do the following with this program.".light_yellow +options.each do |option| + puts option.magenta +end def main #initialize solar system and planets @@ -23,19 +24,19 @@ def main # control loop for program next steps next_step = "" until next_step == "exit" - puts "What would you like to do? Options - 'list planets', 'planet details', 'add planet', or 'exit'" + puts "What would you like to do? Options - 'list planets', 'planet details', 'add planet', or 'exit'".light_cyan next_step = gets.chomp.downcase if next_step == "list planets" - list = food_way.list_planets + list = food_way.list_planets.white puts list elsif next_step == "planet details" puts "Which planet would you like to learn more about?" user_planet = gets.chomp found_planet = food_way.find_planet_by_name(user_planet) if found_planet == nil - puts "Sorry, that planet does not exist in the Food Way Solar System. Check your spelling or try a different planet." + puts "Sorry, that planet does not exist in the Food Way Solar System. Check your spelling or try a different planet.".red.on_blue else - puts found_planet.summary + puts found_planet.summary.light_magenta end elsif next_step == "add planet" puts "What planet would you like to add?" @@ -50,8 +51,10 @@ def main planet_fun = gets.chomp adding_planet = Planet.new(new_planet, planet_color, planet_mass, planet_distance, planet_fun) food_way.add_planet(adding_planet) + elsif next_step == "exit" + break else - puts "This is not an option. Try again." + puts "This is not an option. Try again.".blue.on_white end end end From 1ee74a6bc45bb2ffd35a4434b4c5328e8cc5e3e4 Mon Sep 17 00:00:00 2001 From: Angela Date: Tue, 26 Feb 2019 13:49:46 -0800 Subject: [PATCH 24/24] fixed error in distance --- main.rb | 2 +- planet.rb | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/main.rb b/main.rb index cebc3d76..18f92a9b 100644 --- a/main.rb +++ b/main.rb @@ -12,7 +12,7 @@ def main #initialize solar system and planets food_way = SolarSystem.new("Pad Thai Star") - burger = Planet.new("Burger", "brown", 3453, 234, "Inhabitants of burger really like to eat meat.") + burger = Planet.new("Burger", "brown", 23, 235, "Inhabitants of planet Burger really like to eat meat.") salad = Planet.new("Salad", "green and others depending on time", 236, 235, "The planet Salad changes colors depending on the season.") pho = Planet.new("Pho", "white and brown", 75, 234854, "The planet Pho always smells delicious.") diff --git a/planet.rb b/planet.rb index 39ccc578..1277d093 100644 --- a/planet.rb +++ b/planet.rb @@ -2,16 +2,8 @@ class Planet def initialize(name, color, mass_kg, distance_from_the_sun_km, fun_fact) @name = name @color = color - if mass_kg.class != Integer || mass_kg < 0 - @mass_kg = 0 - else - @mass_kg = mass_kg - end - if distance_from_the_sun_km != Integer || distance_from_the_sun_km < 0 - @distance_from_the_sun_km = 0 - else - @distance_from_the_sun_km = distance_from_the_sun_km - end + mass_kg.class != Integer || mass_kg < 0 ? @mass_kg = 0 : @mass_kg = mass_kg + distance_from_the_sun_km.class != Integer || distance_from_the_sun_km < 0 ? @distance_from_the_sun_km = 0 : @distance_from_the_sun_km = distance_from_the_sun_km @fun_fact = fun_fact end