From 579ba952425d7b987386a3b3208212292db77ed9 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Mon, 21 Sep 2020 23:24:59 -0700 Subject: [PATCH 01/24] Initial commit of class planet document. So far constructor and reader methods have been added --- planet.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 planet.rb diff --git a/planet.rb b/planet.rb new file mode 100644 index 00000000..be883614 --- /dev/null +++ b/planet.rb @@ -0,0 +1,12 @@ +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 \ No newline at end of file From a9ee4f3012f38dd707f2e725df739594be4c7b48 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Mon, 21 Sep 2020 23:33:06 -0700 Subject: [PATCH 02/24] updated planet and created main.rb file --- main.rb | 9 +++++++++ planet.rb | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 main.rb diff --git a/main.rb b/main.rb new file mode 100644 index 00000000..fc3ef32d --- /dev/null +++ b/main.rb @@ -0,0 +1,9 @@ +require_relative 'planet' + +def main + +end + + + +main \ No newline at end of file diff --git a/planet.rb b/planet.rb index be883614..854edc4d 100644 --- a/planet.rb +++ b/planet.rb @@ -9,4 +9,10 @@ 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 \ No newline at end of file +end + +earth = Planet.new('Earth', "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") + +puts earth.name +puts earth.fun_fact +# earth.color = "pink" \ No newline at end of file From 53d51f5562d76df1ee04d7efce450755116b6079 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Tue, 22 Sep 2020 00:37:54 -0700 Subject: [PATCH 03/24] Added solar system to project --- solar_system.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 solar_system.rb diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..7bf445ba --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,27 @@ + +class SolarSystem + + attr_reader :star_name, :planets + + def initialize(star_name) + @star_name = star_name + @planets = [] + end + + def SolarSystem(add_planet) + + end + + def SolarSystem(list_planets) + counter = 1 + list_planets.each do |planet| + return + "Planets orbiting #{star_name}\n #{counter}. #{planet}\n" + counter += 1 + end + end + + + + +end \ No newline at end of file From 78bb624ab3a70c67a8d0a63066f66a1638a4702c Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Tue, 22 Sep 2020 00:39:07 -0700 Subject: [PATCH 04/24] Working on def summary --- main.rb | 3 +++ planet.rb | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/main.rb b/main.rb index fc3ef32d..6154b44a 100644 --- a/main.rb +++ b/main.rb @@ -1,9 +1,12 @@ require_relative 'planet' +require 'colorize' +require 'colorized_string' def main end +pp earth.summary main \ No newline at end of file diff --git a/planet.rb b/planet.rb index 854edc4d..3685789e 100644 --- a/planet.rb +++ b/planet.rb @@ -9,9 +9,27 @@ 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 + + def summary + return "Name: #{@name}\n Color: #{@colorcolor}\n Mass: #{@mass_kgmass_kg}\n Distance from the Sun: #{@distance_from_sun_km}\n Fun Fact: #{@fun_fact}" + end + + earth = Planet.new('Earth', "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") + + pp earth + + + + + + end -earth = Planet.new('Earth', "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") + + + + + puts earth.name puts earth.fun_fact From d210618a7eeffbcedda4c62915e14c431075cd0f Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Tue, 22 Sep 2020 15:31:35 -0700 Subject: [PATCH 05/24] added a test file for planet --- planet_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 planet_test.rb diff --git a/planet_test.rb b/planet_test.rb new file mode 100644 index 00000000..49386b2a --- /dev/null +++ b/planet_test.rb @@ -0,0 +1,9 @@ +require 'minitest/autorun' +require 'minitest/reporters' +require_relative 'planet' + +Minitest::Reporters.use! + +describe "planet" do + +end \ No newline at end of file From d7101244feb3df6abeec750f118dc69ee4f89c25 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Tue, 22 Sep 2020 15:32:26 -0700 Subject: [PATCH 06/24] created new instance of earth and tested code from planet class --- main.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.rb b/main.rb index 6154b44a..cd05aced 100644 --- a/main.rb +++ b/main.rb @@ -2,11 +2,12 @@ require 'colorize' require 'colorized_string' + def main end -pp earth.summary - +earth = Planet.new("earth", "blue-green",-1,2,"I live on it") +puts earth.summary main \ No newline at end of file From 260d7d46ffa05ea34bc58e29e9981b6474341447 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Tue, 22 Sep 2020 15:33:17 -0700 Subject: [PATCH 07/24] Added the summary block and added optional data validation for mass and distance --- planet.rb | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/planet.rb b/planet.rb index 3685789e..537fe00e 100644 --- a/planet.rb +++ b/planet.rb @@ -2,22 +2,30 @@ class Planet attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact + def mass_kg=(mass_kg) + if mass_kg < 0 + raise ArgumentError.new('Mass must be greater than 0.') + end + end + + def distance_from_sun_km=(distance_from_sun_km) + if distance_from_sun_km < 0 + raise ArgumentError.new('Distance from sun must be greater than 0.') + end + end + 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 + self.mass_kg = mass_kg + self.distance_from_sun_km = distance_from_sun_km @fun_fact = fun_fact end def summary - return "Name: #{@name}\n Color: #{@colorcolor}\n Mass: #{@mass_kgmass_kg}\n Distance from the Sun: #{@distance_from_sun_km}\n Fun Fact: #{@fun_fact}" + " Name: #{@name}\n Color: #{@color}\n Mass: #{mass_kg}\n Distance from the Sun: #{distance_from_sun_km}\n Fun Fact: #{@fun_fact}" end - earth = Planet.new('Earth', "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") - - pp earth - @@ -25,12 +33,3 @@ def summary end - - - - - - -puts earth.name -puts earth.fun_fact -# earth.color = "pink" \ No newline at end of file From 17f2edb9e76f900ce82158ea152e489591b806ef Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Tue, 22 Sep 2020 16:12:24 -0700 Subject: [PATCH 08/24] Trying to get logic in minitest to run for ArgumentError, but no luck --- planet.rb | 4 +--- planet_test.rb | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/planet.rb b/planet.rb index 537fe00e..f93f9b9c 100644 --- a/planet.rb +++ b/planet.rb @@ -3,9 +3,7 @@ class Planet attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact def mass_kg=(mass_kg) - if mass_kg < 0 - raise ArgumentError.new('Mass must be greater than 0.') - end + raise ArgumentError, 'Mass must be greater than 0.' if mass_kg < 0 end def distance_from_sun_km=(distance_from_sun_km) diff --git a/planet_test.rb b/planet_test.rb index 49386b2a..94004b4b 100644 --- a/planet_test.rb +++ b/planet_test.rb @@ -5,5 +5,28 @@ Minitest::Reporters.use! describe "planet" do - + + it "will return a string" do + + #Arrange + earth = Planet.new("earth", "blue-green",5,2,"I live on it") + + #Act + puts earth.summary + + #Assert + expect(earth.summary).must_be_instance_of String + end + + it "will raise an error if mass_kg is less than 0" do + + #Arrange + Planet.new("earth", "blue-green",-5,2,"I live on it") + + #Assert + expect { + Planet.new("earth", "blue-green",-5,2,"I live on it") + }.must_raise ArgumentError + end + end \ No newline at end of file From 4276d83da2b146de407dd2f32b6baba28f40ce29 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Tue, 22 Sep 2020 16:40:52 -0700 Subject: [PATCH 09/24] Solved issues with tests and it will now properly test for ArgumentError. --- planet_test.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/planet_test.rb b/planet_test.rb index 94004b4b..be1944e1 100644 --- a/planet_test.rb +++ b/planet_test.rb @@ -20,13 +20,18 @@ it "will raise an error if mass_kg is less than 0" do - #Arrange - Planet.new("earth", "blue-green",-5,2,"I live on it") - #Assert expect { Planet.new("earth", "blue-green",-5,2,"I live on it") }.must_raise ArgumentError end + it "will raise an error if distance_from_sun_km is less than 0" do + #Assert + expect { + Planet.new("earth", "blue-green",5,-2,"I live on it") + }.must_raise ArgumentError + + end + end \ No newline at end of file From d18bf0c644bf739c470f4c79c3a130a1e56e658b Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Tue, 22 Sep 2020 16:41:40 -0700 Subject: [PATCH 10/24] Added 2 new methods 'add_planet' and 'list_planets' --- solar_system.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/solar_system.rb b/solar_system.rb index 7bf445ba..4dedeba7 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -8,20 +8,21 @@ def initialize(star_name) @planets = [] end - def SolarSystem(add_planet) - + def add_planet(planet) + @planets << planet end - def SolarSystem(list_planets) + def list_planets counter = 1 - list_planets.each do |planet| - return - "Planets orbiting #{star_name}\n #{counter}. #{planet}\n" - counter += 1 + @planets.each do |planet| + "Planets orbiting #{@star_name}:\n#{counter}. #{planet}\n" + counter += 1 end end + + end \ No newline at end of file From c0b3a8fabb7efe9098884747d8d3f5c4da397621 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Tue, 22 Sep 2020 21:24:14 -0700 Subject: [PATCH 11/24] Added an instance of found_planet to the main rb --- main.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/main.rb b/main.rb index cd05aced..6eb384cc 100644 --- a/main.rb +++ b/main.rb @@ -1,13 +1,21 @@ require_relative 'planet' -require 'colorize' -require 'colorized_string' - +require_relative 'solar_system' def main end -earth = Planet.new("earth", "blue-green",-1,2,"I live on it") +solar_system = SolarSystem.new("Sol") +earth = Planet.new("earth", "blue-green",1,2,"I live on it") +solar_system.add_planet(earth) + +# list = solar_system.list_planets +# puts list +# main + +found_planet = solar_system.find_planet_by_name("earth") +puts found_planet + +puts found_planet.summary -puts earth.summary main \ No newline at end of file From a808e92b0e82d9f3c8c2fe75e1543d7bb04188de Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Tue, 22 Sep 2020 21:25:15 -0700 Subject: [PATCH 12/24] Had to rework @mass_kg and @distance from sun--added the validation directly into the constuctor function --- planet.rb | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/planet.rb b/planet.rb index f93f9b9c..e639c446 100644 --- a/planet.rb +++ b/planet.rb @@ -2,26 +2,28 @@ class Planet attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact - def mass_kg=(mass_kg) - raise ArgumentError, 'Mass must be greater than 0.' if mass_kg < 0 - end - - def distance_from_sun_km=(distance_from_sun_km) - if distance_from_sun_km < 0 - raise ArgumentError.new('Distance from sun must be greater than 0.') - end - end + # def mass_kg=(mass_kg) + # raise ArgumentError, 'Mass must be greater than 0.' if mass_kg < 0 + # end + # + # def distance_from_sun_km=(distance_from_sun_km) + # if distance_from_sun_km < 0 + # raise ArgumentError.new('Distance from sun must be greater than 0.') + # end + # end def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact) @name = name @color = color - self.mass_kg = mass_kg - self.distance_from_sun_km = distance_from_sun_km + @mass_kg = mass_kg + raise ArgumentError, 'Mass must be greater than 0.' if mass_kg < 0 + @distance_from_sun_km = distance_from_sun_km + raise ArgumentError, 'Distance from sun must be greater than 0.' if distance_from_sun_km < 0 @fun_fact = fun_fact end def summary - " Name: #{@name}\n Color: #{@color}\n Mass: #{mass_kg}\n Distance from the Sun: #{distance_from_sun_km}\n Fun Fact: #{@fun_fact}" + " Name: #{@name}\n Color: #{@color}\n Mass: #{@mass_kg}\n Distance from the Sun: #{@distance_from_sun_km}\n Fun Fact: #{@fun_fact}" end From 131b7fd3efeca93f7405de053b681e64226e33d6 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Tue, 22 Sep 2020 21:26:19 -0700 Subject: [PATCH 13/24] Added find_planet_by_name method --- solar_system.rb | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/solar_system.rb b/solar_system.rb index 4dedeba7..52f2a057 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -13,16 +13,22 @@ def add_planet(planet) end def list_planets - counter = 1 - @planets.each do |planet| - "Planets orbiting #{@star_name}:\n#{counter}. #{planet}\n" - counter += 1 + list = "\nPlanets orbiting #{star_name}:\n" + @planets.each_with_index do |planet, index| + index += 1 + list += "#{index}. #{planet.name}\n" + end + return list end - end - - - - - -end \ No newline at end of file + def find_planet_by_name(name) + planet_name = name.upcase + @planets.each do |planet| + if planet.name.upcase == planet_name + return planet + else + return "Sorry,this planet is in the process of being created many light years away and cannot be located just yet." + end + end + end +end From 8d49a9dc0052a2e451f380070e5d16c9448322d2 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Wed, 23 Sep 2020 00:22:48 -0700 Subject: [PATCH 14/24] found bug in 'view planet details' option...but now gone --- main.rb | 77 +++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 10 deletions(-) diff --git a/main.rb b/main.rb index 6eb384cc..cf0fbb21 100644 --- a/main.rb +++ b/main.rb @@ -3,19 +3,76 @@ def main + #Create a solar system, planets, and add them to the planets array in the solar system + solar_system = SolarSystem.new("luna") + + koopa_troopa_town = Planet.new("koopa troopa town","red and green", 6.972e24, 1.283e7, "It takes a while for inhabitants to come out of their shell.") + solar_system.add_planet(koopa_troopa_town) + + yoshi_land = Planet.new("yoshi land", "green", 2, 1.5, "My full planet name is T. Yoshisaur Munchakoopas" ) + solar_system.add_planet(yoshi_land) + + mario_world = Planet.new("mario world", "red", 5.432e56, 100000, "You'll find that everything here is super!") + solar_system.add_planet(mario_world) + + earth = Planet.new("earth", "blue-green",6.972e24,1.283e7,"I live on it") + solar_system.add_planet(earth) + + bowserville = Planet.new("bowserville", "orange, red, and green", 100000000e34, 60000, "Bwa ha ha ha!" ) + solar_system.add_planet(bowserville) + + luigi_lagoon = Planet.new("luigi lagoon", "green", 343439, 232939, "Luigi TIme!!") + solar_system.add_planet(luigi_lagoon) + + princess_peach_paradise = Planet.new("princess peach paradise", "peach", 34342, 45645, "Peachy!") + solar_system.add_planet(princess_peach_paradise) + + + + #Control loop that repeatedly asks user what to do next + repeat = true + + until repeat == false + puts "*" * 50 + puts "Marioooo time! What would you like to do next?\nYou can:\n" + puts "1. See a list of planets by typing 'list'\n" + puts "2. View planet details of your favorite planet by typing 'details'\n" + puts "3. Exit the program by typing 'exit'\n\n" + puts "Waiting for your input.... " + input = gets.chomp + + case + when input == "list" + repeat = false + list = solar_system.list_planets + puts list + when input == "details" + puts "What planet are you interested in learning more about?" + input = gets.chomp.to_s + summary = solar_system.find_planet_by_name(input) + puts summary + repeat = false + end + end end -solar_system = SolarSystem.new("Sol") -earth = Planet.new("earth", "blue-green",1,2,"I live on it") -solar_system.add_planet(earth) +main -# list = solar_system.list_planets -# puts list -# main -found_planet = solar_system.find_planet_by_name("earth") -puts found_planet -puts found_planet.summary -main \ No newline at end of file + + + + + + + + + + +# main +# + +# end +# main \ No newline at end of file From 0edd1e42845e05b4807e586ec50822d3f5813735 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Wed, 23 Sep 2020 00:23:34 -0700 Subject: [PATCH 15/24] Added 'return' to summary method --- planet.rb | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/planet.rb b/planet.rb index e639c446..c788f58f 100644 --- a/planet.rb +++ b/planet.rb @@ -2,16 +2,6 @@ class Planet attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact - # def mass_kg=(mass_kg) - # raise ArgumentError, 'Mass must be greater than 0.' if mass_kg < 0 - # end - # - # def distance_from_sun_km=(distance_from_sun_km) - # if distance_from_sun_km < 0 - # raise ArgumentError.new('Distance from sun must be greater than 0.') - # end - # end - def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact) @name = name @color = color @@ -23,13 +13,9 @@ def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact) end def summary - " Name: #{@name}\n Color: #{@color}\n Mass: #{@mass_kg}\n Distance from the Sun: #{@distance_from_sun_km}\n Fun Fact: #{@fun_fact}" + summary = " Name: #{@name}\n Color: #{@color}\n Mass: #{@mass_kg}\n Distance from the Sun:#{@distance_from_sun_km}\n Fun Fact: #{@fun_fact}" + return summary end - - - - - end From fd7b3ec0ce0228aaa45f9fd7f4d3778d72420429 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Wed, 23 Sep 2020 00:24:12 -0700 Subject: [PATCH 16/24] Not sure what the change was, but pushing it through --- solar_system.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/solar_system.rb b/solar_system.rb index 52f2a057..cb28df03 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -1,3 +1,4 @@ +require_relative 'planet' class SolarSystem @@ -21,14 +22,12 @@ def list_planets return list end - def find_planet_by_name(name) - planet_name = name.upcase - @planets.each do |planet| - if planet.name.upcase == planet_name - return planet - else - return "Sorry,this planet is in the process of being created many light years away and cannot be located just yet." + def find_planet_by_name(input_name) + @planets.each do |single_planet| + if single_planet.name.downcase == input_name.downcase + return single_planet.summary + end + end + return "Sorry,this planet is in the process of being created many light years away and cannot be located just yet." end - end - end end From 5d7310be5c00d46558e739f1755cc42a2c299248 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Wed, 23 Sep 2020 01:03:13 -0700 Subject: [PATCH 17/24] program fully functional. Fixed loop so that it only quits when user enters 'exit' --- main.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/main.rb b/main.rb index cf0fbb21..ba8844f3 100644 --- a/main.rb +++ b/main.rb @@ -31,19 +31,18 @@ def main #Control loop that repeatedly asks user what to do next repeat = true - until repeat == false puts "*" * 50 puts "Marioooo time! What would you like to do next?\nYou can:\n" puts "1. See a list of planets by typing 'list'\n" puts "2. View planet details of your favorite planet by typing 'details'\n" - puts "3. Exit the program by typing 'exit'\n\n" + puts "3. Add a planet to the Mario Universe collection by typing 'add'\n" + puts "4. Exit the program by typing 'exit'\n\n" puts "Waiting for your input.... " input = gets.chomp case when input == "list" - repeat = false list = solar_system.list_planets puts list when input == "details" @@ -51,7 +50,11 @@ def main input = gets.chomp.to_s summary = solar_system.find_planet_by_name(input) puts summary - repeat = false + when input == "add" + solar_system.add_new_planet + puts "Let's see your new planet!" + when input == "exit" + exit end end end From d9a985cb5ca2b90f76c1115c78551b8d6ee3d5ee Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Wed, 23 Sep 2020 01:03:58 -0700 Subject: [PATCH 18/24] Added 'add_new_planet' method to solar system --- solar_system.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/solar_system.rb b/solar_system.rb index cb28df03..6aeefa2f 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -29,5 +29,22 @@ def find_planet_by_name(input_name) end end return "Sorry,this planet is in the process of being created many light years away and cannot be located just yet." - end + end + + def add_new_planet + puts "It's a-me, Mario! Add some information about your new planet:" + puts "name:" + new_name = gets.chomp + puts "color:" + new_color = gets.chomp + puts "mass_kg (integer only):" + new_mass = gets.chomp.to_i + puts "distance from sun (must be integer in km):" + new_distance = gets.chomp.to_i + puts "What is your fun-a fact?" + new_fun_fact = gets.chomp + + new_name = Planet.new(new_name,new_color,new_mass,new_distance,new_fun_fact) + add_planet(new_name) + end end From 99e7f65d3168d1d9bd10038146607ef159df98df Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Wed, 23 Sep 2020 02:03:33 -0700 Subject: [PATCH 19/24] added colorize gem --- main.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.rb b/main.rb index ba8844f3..feb3c268 100644 --- a/main.rb +++ b/main.rb @@ -1,5 +1,7 @@ require_relative 'planet' require_relative 'solar_system' +require 'colorize' +require 'colorized_string' def main @@ -32,8 +34,9 @@ def main #Control loop that repeatedly asks user what to do next repeat = true until repeat == false + puts puts "*" * 50 - puts "Marioooo time! What would you like to do next?\nYou can:\n" + puts "Marioooo time! What would you like to do next?\nYou can:\n".colorize(:light_green) puts "1. See a list of planets by typing 'list'\n" puts "2. View planet details of your favorite planet by typing 'details'\n" puts "3. Add a planet to the Mario Universe collection by typing 'add'\n" @@ -55,6 +58,8 @@ def main puts "Let's see your new planet!" when input == "exit" exit + else + puts "\nInvalid Entry. Please read the instructions carefully and retype your answer.".upcase.colorize(:red) end end end From 4a9b778c7f0be765d26074e206845464a5694008 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Wed, 23 Sep 2020 02:03:49 -0700 Subject: [PATCH 20/24] added colorize gem --- planet.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planet.rb b/planet.rb index c788f58f..a5d01c29 100644 --- a/planet.rb +++ b/planet.rb @@ -13,7 +13,7 @@ def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact) end def summary - summary = " Name: #{@name}\n Color: #{@color}\n Mass: #{@mass_kg}\n Distance from the Sun:#{@distance_from_sun_km}\n Fun Fact: #{@fun_fact}" + summary = "\n Name: #{@name}\n Color: #{@color}\n Mass: #{@mass_kg}\n Distance from the Sun:#{@distance_from_sun_km}\n Fun Fact: #{@fun_fact}\n\n".colorize(:green) return summary end From 1086e06c4db4cc598c4384a55130009c5e3c9a80 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Wed, 23 Sep 2020 02:04:01 -0700 Subject: [PATCH 21/24] added colorize gem --- solar_system.rb | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/solar_system.rb b/solar_system.rb index 6aeefa2f..b722e0d4 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -1,4 +1,6 @@ require_relative 'planet' +require 'colorize' +require 'colorized_string' class SolarSystem @@ -14,7 +16,7 @@ def add_planet(planet) end def list_planets - list = "\nPlanets orbiting #{star_name}:\n" + list = "\nPlanets orbiting #{star_name}:\n".colorize(:green) @planets.each_with_index do |planet, index| index += 1 list += "#{index}. #{planet.name}\n" @@ -24,11 +26,9 @@ def list_planets def find_planet_by_name(input_name) @planets.each do |single_planet| - if single_planet.name.downcase == input_name.downcase - return single_planet.summary + return single_planet.summary if single_planet.name.downcase == input_name.downcase end - end - return "Sorry,this planet is in the process of being created many light years away and cannot be located just yet." + return "\nSorry,this planet is in the process of being created many light years away and cannot be located just yet.".upcase.colorize(:red) end def add_new_planet @@ -37,10 +37,16 @@ def add_new_planet new_name = gets.chomp puts "color:" new_color = gets.chomp - puts "mass_kg (integer only):" + puts "mass_kg (integer only - do not spell out number):" new_mass = gets.chomp.to_i - puts "distance from sun (must be integer in km):" + if new_mass < 1 + raise ArgumentError, 'Mass must be an integer and it must be greater than 0.'.colorize(:yellow) + end + puts "distance from sun (integer only - do not spell out number):" new_distance = gets.chomp.to_i + if new_distance < 1 + raise ArgumentError, "Distance from sun must be greater than 0.".colorize(:yellow) + end puts "What is your fun-a fact?" new_fun_fact = gets.chomp From b32b4cbadea88ea08b855c37c89dfa8ad9856a50 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Wed, 23 Sep 2020 02:10:42 -0700 Subject: [PATCH 22/24] required colorize gem so that test works properly --- planet_test.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/planet_test.rb b/planet_test.rb index be1944e1..ac456b09 100644 --- a/planet_test.rb +++ b/planet_test.rb @@ -1,6 +1,8 @@ require 'minitest/autorun' require 'minitest/reporters' require_relative 'planet' +require 'colorize' +require 'colorized_string' Minitest::Reporters.use! From b0381c564dfc157ac263e1ddfade96e5d959eee2 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Wed, 23 Sep 2020 02:58:08 -0700 Subject: [PATCH 23/24] added some clarifying comments to 'add_new_planet' method --- main.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/main.rb b/main.rb index feb3c268..4055b9d1 100644 --- a/main.rb +++ b/main.rb @@ -32,6 +32,7 @@ def main #Control loop that repeatedly asks user what to do next + # Only way to exit program is to type 'exit' repeat = true until repeat == false puts From 03ae0350eff6932eb166a807ced24ef894da8bd0 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Wed, 23 Sep 2020 02:58:56 -0700 Subject: [PATCH 24/24] added comment to add_new_planet method --- solar_system.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/solar_system.rb b/solar_system.rb index b722e0d4..b6d76b46 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -31,6 +31,7 @@ def find_planet_by_name(input_name) return "\nSorry,this planet is in the process of being created many light years away and cannot be located just yet.".upcase.colorize(:red) end + #Add argument error to mass and distance input since they are not going through the initialize function def add_new_planet puts "It's a-me, Mario! Add some information about your new planet:" puts "name:" @@ -39,14 +40,14 @@ def add_new_planet new_color = gets.chomp puts "mass_kg (integer only - do not spell out number):" new_mass = gets.chomp.to_i - if new_mass < 1 - raise ArgumentError, 'Mass must be an integer and it must be greater than 0.'.colorize(:yellow) - end + if new_mass < 1 + raise ArgumentError, 'Mass must be an integer and it must be greater than 0.'.colorize(:yellow) + end puts "distance from sun (integer only - do not spell out number):" new_distance = gets.chomp.to_i - if new_distance < 1 - raise ArgumentError, "Distance from sun must be greater than 0.".colorize(:yellow) - end + if new_distance < 1 + raise ArgumentError, "Distance from sun must be greater than 0.".colorize(:yellow) + end puts "What is your fun-a fact?" new_fun_fact = gets.chomp