From a08d1d2305c01a657b053dc5fb4848623a4180d1 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 26 Feb 2019 07:04:07 -0800 Subject: [PATCH 01/27] created planet.rb file with planet class, reader attribute, and initialize method. --- planet.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 planet.rb diff --git a/planet.rb b/planet.rb new file mode 100644 index 00000000..65bef19a --- /dev/null +++ b/planet.rb @@ -0,0 +1,13 @@ +class Planet + attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact, :twang_level, :likelihood_to_be_loved_by_yanks + + def initialize(name, color, mass, distance, fun_fact, twang_level, likelihood_to_be_loved_by_yanks) + @name = name.capitalize + @color = color + @mass_kg = mass_kg + @distance_from_sun_km = distance_from_sun_km + @fun_fact = fun_fact + @twang_level = twang_level + @likelihood_to_be_loved_by_yanks = likelihood_to_be_loved_by_yanks + end +end From 3fe393796ac38fd8b66ed5980604db808a77ce0f Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 26 Feb 2019 07:07:59 -0800 Subject: [PATCH 02/27] added main.rb file with empty main method and summary method to planet.rb file --- main.rb | 0 planet.rb | 7 +++++++ 2 files changed, 7 insertions(+) create mode 100644 main.rb diff --git a/main.rb b/main.rb new file mode 100644 index 00000000..e69de29b diff --git a/planet.rb b/planet.rb index 65bef19a..e707ba46 100644 --- a/planet.rb +++ b/planet.rb @@ -10,4 +10,11 @@ def initialize(name, color, mass, distance, fun_fact, twang_level, likelihood_to @twang_level = twang_level @likelihood_to_be_loved_by_yanks = likelihood_to_be_loved_by_yanks end + + def summary + return "The planet #{@name} is the color #{@color} has a mass of #{@mass} kg, and is #{@distance_from_sun_km} km from the sun. + It #{fun_fact}, is know to have a twang level of #{twang_level} out of 5, and is #{likelihood_to_be_loved_by_yanks}% likely + to be loved by out-of-towners visiting the galaxy of Nashville for a bachelor or bachelorette party, never to return again.") +end + end From 800a9aff0cc345f6674fef4ecea2b12d36488f34 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 26 Feb 2019 07:11:03 -0800 Subject: [PATCH 03/27] added argument errors to planet.rb for mass_kg and distance_from_sun_km --- planet.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/planet.rb b/planet.rb index e707ba46..d658ccd9 100644 --- a/planet.rb +++ b/planet.rb @@ -9,6 +9,12 @@ def initialize(name, color, mass, distance, fun_fact, twang_level, likelihood_to @fun_fact = fun_fact @twang_level = twang_level @likelihood_to_be_loved_by_yanks = likelihood_to_be_loved_by_yanks + if mass <= 0 + return raise ArgumentError, 'Planet mass must be larger than 0' + end + if distance <= 0 + return raise ArgumentError, 'Planet distance must be larger than 0' + end end def summary From b7e2e8bd76ec78e1dcdac3471cb2d706cbe7808b Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 26 Feb 2019 07:12:49 -0800 Subject: [PATCH 04/27] added country music planets to my main.rb --- main.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/main.rb b/main.rb index e69de29b..695fc408 100644 --- a/main.rb +++ b/main.rb @@ -0,0 +1,17 @@ +require_relative "planet" +require 'pry' + +def main + + elvis = Planet.new('Elvis', 'shiny', 159, 20, 'recorded more than 600 songs, but did not write any of them', 3.5, 85) + hank_sr = Planet.new('Hank Sr', 'white as hell', 72, 30, 'recorded 14 songs as his alter ego, Luke the Drifter', 4.5, 10) + dolly = Planet.new ('Dolly', 'canary yellow', 52, 18, 'once entered a Dolly look-alike drag queen contest and lost', 4.8, 90) + patsy = Planet.new ('Patsy','chesnut', 70, 40, 'enjoys walking after midnight', 3.4, 0.5) + garth = Planet.new ('Garth', 'off-white', 83, 45, 'is responsible for the the most insufferable variety of country boi', 4.6, 99) + johnny = Planet.new ('Johnny', 'coal black', 86, 5, 'was a campaigner for Native American rights and wrote a song titled “Old Apache Squaw” which his record company thought it too radical', 3.6, 91) + reba = Planet.new ('Reba', 'red', 60, 'is the only country female solo act to have a No. 1 hit in four straight decades: the 1980s, 90s, 00s and 10s', 5.0, 70) + willie = Planet.new ('Willie', 'old', 70, 7, 'ran into a burning house to save his pound of Columbian grass', 3.8, 15) + +end + +main \ No newline at end of file From eb243128f0790e99dcf5028b28fafccb11e5dbee Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 26 Feb 2019 07:16:51 -0800 Subject: [PATCH 05/27] created solar_system.rb with class and ininitialize method --- main.rb | 10 ++++++++++ solar_system.rb | 15 +++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 solar_system.rb diff --git a/main.rb b/main.rb index 695fc408..6bca18a6 100644 --- a/main.rb +++ b/main.rb @@ -3,6 +3,8 @@ def main + solar_system = SolarSystem.new('Sol') + elvis = Planet.new('Elvis', 'shiny', 159, 20, 'recorded more than 600 songs, but did not write any of them', 3.5, 85) hank_sr = Planet.new('Hank Sr', 'white as hell', 72, 30, 'recorded 14 songs as his alter ego, Luke the Drifter', 4.5, 10) dolly = Planet.new ('Dolly', 'canary yellow', 52, 18, 'once entered a Dolly look-alike drag queen contest and lost', 4.8, 90) @@ -12,6 +14,14 @@ def main reba = Planet.new ('Reba', 'red', 60, 'is the only country female solo act to have a No. 1 hit in four straight decades: the 1980s, 90s, 00s and 10s', 5.0, 70) willie = Planet.new ('Willie', 'old', 70, 7, 'ran into a burning house to save his pound of Columbian grass', 3.8, 15) + solar_system.add_planet(elvis) + solar_system.add_planet(hank_sr) + solar_system.add_planet(dolly) + solar_system.add_planet(patsy) + solar_system.add_planet(garth) + solar_system.add_planet(johnny) + solar_system.add_planet(reba) + end main \ No newline at end of file diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..6c7d9873 --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,15 @@ +require_relative "planet" +require_relative "solar_system" +require "pry" + +class SolarSystem + def initialize(star_name) + @star_name = star_name + @planets = [] + end + + #create add planet method + + #create list planets method + +end From bd10d6f3c410f69ae578ee445bb6c3c60255f9b7 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 26 Feb 2019 07:21:43 -0800 Subject: [PATCH 06/27] added solar_system.new to main.rb, added current planets. --- main.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.rb b/main.rb index 6bca18a6..d2749a52 100644 --- a/main.rb +++ b/main.rb @@ -21,7 +21,7 @@ def main solar_system.add_planet(garth) solar_system.add_planet(johnny) solar_system.add_planet(reba) - + end main \ No newline at end of file From 55c2de075a478ea19cf6810b6879199f2d329de4 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 26 Feb 2019 07:23:45 -0800 Subject: [PATCH 07/27] attr_reader and add_planet method updated on solar_system.rb --- solar_system.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/solar_system.rb b/solar_system.rb index 6c7d9873..6bc7a56c 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -3,12 +3,16 @@ require "pry" class SolarSystem + attr_reader :star_name, :planets + def initialize(star_name) @star_name = star_name @planets = [] end - #create add planet method + def add_planet(planet) + @planets << planet + end #create list planets method From 2d129b4ec1e51452aacd951883a630737af544b2 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 26 Feb 2019 08:32:24 -0800 Subject: [PATCH 08/27] get_info_new_planet method written...this should help. --- solar_system.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/solar_system.rb b/solar_system.rb index 6bc7a56c..9a6bdcc8 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -14,6 +14,28 @@ def add_planet(planet) @planets << planet end - #create list planets method + def get_info_new_planet + print "\nEnter new planet name: " + planet_name = gets.chomp.to_s + print "\nDescription of #{planet_name}'s color: " + color = gets.chomp.to_s + print "\nDistance of planet from #{@star_name}(km): " + distance = gets.chomp.to_f + print "\nMass of #{planet_name}(kg): " + mass = gets.chomp.to_f + print "\nInteresting fact about #{planet_name}: " + fun_fact = gets.chomp.to_s + print "\nPlease rate the planet's twang on a scale of 0-5.0 #{planet_name}: " + twang_level = gets.chomp.to_f + print "\nPlease rate the planet's likelihood to be beloved in New England, on a scale of 0-100 #{planet_name}: " + likelihood_to_be_loved_by_yanks = gets.chomp.to_s + + new_planet = Planet.new(planet_name, color, distance, mass, fun_fact, twang_level, likelihood_to_be_loved_by_yanks) + + add_planet(new_planet) + print "\nGenerating new data" + end + + # create list of planets end From c54eb55d041f86fd33bbabb660d825577d732073 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 26 Feb 2019 08:36:39 -0800 Subject: [PATCH 09/27] added list_planets to solar_system.rb --- solar_system.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/solar_system.rb b/solar_system.rb index 9a6bdcc8..3cf43c7f 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -36,6 +36,12 @@ def get_info_new_planet print "\nGenerating new data" end - # create list of planets - + def list_planets + list = "\nPlanets in the Country Music Universe:\n" + @planets.each_with_index do |planet, index| + index += 1 + list += "#{index}. #{planet.name}\n" + end + return list + end end From 90ffcd9909d8b6687e6cb255f7e5d86c3de1f36f Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 26 Feb 2019 08:55:43 -0800 Subject: [PATCH 10/27] working on list of options for the user. planning to call each method when the user requests. i'm reading ahead here, so returning to the methods... --- main.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/main.rb b/main.rb index d2749a52..7ea5bb7a 100644 --- a/main.rb +++ b/main.rb @@ -22,6 +22,34 @@ def main solar_system.add_planet(johnny) solar_system.add_planet(reba) + puts "Country Music Planetary Database Menu\n" + puts "1. List Planets\n" + puts "2. Planet Information\n" + puts "4. Distance Calculator\n" + puts "5. Exit\n" + + loop do + print "\nEnter database selection: " + input = gets.chomp.to_s + case + when input == "1" + puts solar_system.list_planets + when input == "2" + planet = solar_system.get_planet_name + puts planet.summary + when input == "3" + solar_system.add_a_planet + puts "\n...Entered into system. Thank You." + when input == "4" + solar_system.find_distance_between + when input == "5" + exit + when input + # need to find the best way to reject all letters + puts "\nError. Invalid input." + end + end + end main \ No newline at end of file From d35a93e4e16992d2765811d0f58c4859ba175ac4 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 26 Feb 2019 09:02:26 -0800 Subject: [PATCH 11/27] find planet method, not sure it works yet --- main.rb | 19 +++++-------------- solar_system.rb | 9 +++++++++ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/main.rb b/main.rb index 7ea5bb7a..11652757 100644 --- a/main.rb +++ b/main.rb @@ -25,28 +25,19 @@ def main puts "Country Music Planetary Database Menu\n" puts "1. List Planets\n" puts "2. Planet Information\n" - puts "4. Distance Calculator\n" - puts "5. Exit\n" + puts "3. Distance Calculator\n" + puts "4. Exit\n" loop do - print "\nEnter database selection: " - input = gets.chomp.to_s + #prompt to enter selection from above options case when input == "1" - puts solar_system.list_planets when input == "2" - planet = solar_system.get_planet_name - puts planet.summary when input == "3" - solar_system.add_a_planet - puts "\n...Entered into system. Thank You." when input == "4" - solar_system.find_distance_between when input == "5" - exit - when input - # need to find the best way to reject all letters - puts "\nError. Invalid input." + # when input is exit + # when input is invalid end end diff --git a/solar_system.rb b/solar_system.rb index 3cf43c7f..cda0c078 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -44,4 +44,13 @@ def list_planets end return list end + + def find_planet_by_name + @planets.each do |planet| + if planet.name == name.capitalize + return planet + end + end + return raise ArgumentError, "Planet not in solar system" + end end From c82f4dd37df745d1ba89e9f1c30b46ae0b8759a7 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 26 Feb 2019 10:11:15 -0800 Subject: [PATCH 12/27] working on loop do and solar system methods. added get_planet_name and find_planet --- main.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.rb b/main.rb index 11652757..b29164a6 100644 --- a/main.rb +++ b/main.rb @@ -32,10 +32,15 @@ def main #prompt to enter selection from above options case when input == "1" + puts solar_system.list_planets when input == "2" + planet = solar_system.get_planet_name + puts planet.summary when input == "3" + solar_system.add_a_planet + puts "\n...Entered into system. Thank You." when input == "4" - when input == "5" + exit # when input is exit # when input is invalid end From 139928dc6baad58d664864ac57926cfb2d4c870e Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 26 Feb 2019 10:19:00 -0800 Subject: [PATCH 13/27] added way to reject invalid input to my menu - thanks, google! finished methods on solar_system.rb... I think --- main.rb | 6 +++--- solar_system.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/main.rb b/main.rb index b29164a6..54f8bc05 100644 --- a/main.rb +++ b/main.rb @@ -22,7 +22,7 @@ def main solar_system.add_planet(johnny) solar_system.add_planet(reba) - puts "Country Music Planetary Database Menu\n" + puts "Country Music Planetary Menu\n" puts "1. List Planets\n" puts "2. Planet Information\n" puts "3. Distance Calculator\n" @@ -41,8 +41,8 @@ def main puts "\n...Entered into system. Thank You." when input == "4" exit - # when input is exit - # when input is invalid + when input =~ /[[:alpha:]]/ + puts "\nError. Invalid input." end end diff --git a/solar_system.rb b/solar_system.rb index cda0c078..5803ccd0 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -53,4 +53,14 @@ def find_planet_by_name end return raise ArgumentError, "Planet not in solar system" end + + def get_planet_name + print "\nEnter planet name: " + planet = gets.chomp.to_s + return find_planet_by_name(planet) + end + + # need to do method for finding planet distance from sun + # need to do method for finding distance between planets + end From 8b5684100812751a2aef5676bb911312a123e7e7 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 26 Feb 2019 10:22:15 -0800 Subject: [PATCH 14/27] tidying up, removed require pry on files --- main.rb | 1 - solar_system.rb | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/main.rb b/main.rb index 54f8bc05..e1c21e54 100644 --- a/main.rb +++ b/main.rb @@ -1,5 +1,4 @@ require_relative "planet" -require 'pry' def main diff --git a/solar_system.rb b/solar_system.rb index 5803ccd0..e8965fe9 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -1,6 +1,5 @@ require_relative "planet" require_relative "solar_system" -require "pry" class SolarSystem attr_reader :star_name, :planets @@ -61,6 +60,20 @@ def get_planet_name end # need to do method for finding planet distance from sun - # need to do method for finding distance between planets + def get_planet_distance(name) + @planets.each do |planet| + if planet.name == name.capitalize + return planet.distance + end + end + return raise ArgumentError, "Planet not in solar system" + end + # need to do method for finding distance between planets + def find_distance_between + planet1 = get_planet_name + planet2 = get_planet_name + distance = planet1.distance_from_sun_km - planet2.distance_from_sun_km + puts "\nDistance between #{planet1.name} & #{planet2.name}: #{distance.abs} km." + end end From 4fb796c4ae1a36c19588e2841dd85b9e5de65e62 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 26 Feb 2019 10:34:49 -0800 Subject: [PATCH 15/27] tidying --- solar_system.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/solar_system.rb b/solar_system.rb index e8965fe9..f01a3a8b 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -59,7 +59,6 @@ def get_planet_name return find_planet_by_name(planet) end - # need to do method for finding planet distance from sun def get_planet_distance(name) @planets.each do |planet| if planet.name == name.capitalize @@ -69,7 +68,6 @@ def get_planet_distance(name) return raise ArgumentError, "Planet not in solar system" end - # need to do method for finding distance between planets def find_distance_between planet1 = get_planet_name planet2 = get_planet_name From 293795977fd0a5e7c173ea3dd6478739bfd1838a Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Wed, 27 Feb 2019 06:21:05 -0800 Subject: [PATCH 16/27] fixed Planet.new syntax --- main.rb | 85 ++++++++++++++++++++++++------------------------- planet.rb | 9 +++--- solar_system.rb | 2 +- 3 files changed, 47 insertions(+), 49 deletions(-) diff --git a/main.rb b/main.rb index e1c21e54..cd24d25d 100644 --- a/main.rb +++ b/main.rb @@ -1,50 +1,49 @@ require_relative "planet" +require_relative "solar_system" def main - - solar_system = SolarSystem.new('Sol') - - elvis = Planet.new('Elvis', 'shiny', 159, 20, 'recorded more than 600 songs, but did not write any of them', 3.5, 85) - hank_sr = Planet.new('Hank Sr', 'white as hell', 72, 30, 'recorded 14 songs as his alter ego, Luke the Drifter', 4.5, 10) - dolly = Planet.new ('Dolly', 'canary yellow', 52, 18, 'once entered a Dolly look-alike drag queen contest and lost', 4.8, 90) - patsy = Planet.new ('Patsy','chesnut', 70, 40, 'enjoys walking after midnight', 3.4, 0.5) - garth = Planet.new ('Garth', 'off-white', 83, 45, 'is responsible for the the most insufferable variety of country boi', 4.6, 99) - johnny = Planet.new ('Johnny', 'coal black', 86, 5, 'was a campaigner for Native American rights and wrote a song titled “Old Apache Squaw” which his record company thought it too radical', 3.6, 91) - reba = Planet.new ('Reba', 'red', 60, 'is the only country female solo act to have a No. 1 hit in four straight decades: the 1980s, 90s, 00s and 10s', 5.0, 70) - willie = Planet.new ('Willie', 'old', 70, 7, 'ran into a burning house to save his pound of Columbian grass', 3.8, 15) - - solar_system.add_planet(elvis) - solar_system.add_planet(hank_sr) - solar_system.add_planet(dolly) - solar_system.add_planet(patsy) - solar_system.add_planet(garth) - solar_system.add_planet(johnny) - solar_system.add_planet(reba) - - puts "Country Music Planetary Menu\n" - puts "1. List Planets\n" - puts "2. Planet Information\n" - puts "3. Distance Calculator\n" - puts "4. Exit\n" - - loop do - #prompt to enter selection from above options - case - when input == "1" - puts solar_system.list_planets - when input == "2" - planet = solar_system.get_planet_name - puts planet.summary - when input == "3" - solar_system.add_a_planet - puts "\n...Entered into system. Thank You." - when input == "4" - exit - when input =~ /[[:alpha:]]/ - puts "\nError. Invalid input." + solar_system = SolarSystem.new("Sol") + + elvis = Planet.new("Elvis", "shiny", 159, 20, "recorded more than 600 songs, but did not write any of them", 3.5, 85) + hank_sr = Planet.new("Hank Sr", "white as hell", 72, 30, "recorded 14 songs as his alter ego, Luke the Drifter", 4.5, 10) + dolly = Planet.new("Dolly", "canary yellow", 52, 18, "once entered a Dolly look-alike drag queen contest and lost", 4.8, 90) + patsy = Planet.new("Patsy", "chesnut", 70, 40, "enjoys walking after midnight", 3.4, 0.5) + garth = Planet.new("Garth", "off-white", 83, 45, "is responsible for the the most insufferable variety of country boi", 4.6, 99) + johnny = Planet.new("Johnny", "coal black", 86, 5, "was a campaigner for Native American rights", 3.6, 91) + reba = Planet.new("Reba", "red", 60, "is the only country female solo act to have a No. 1 hit in four straight decades: the 1980s, 90s, 00s and 10s", 5.0, 70) + willie = Planet.new("Willie", "old", 70, 7, "ran into a burning house to save his pound of Columbian grass", 3.8, 15) + + solar_system.add_planet(elvis) + solar_system.add_planet(hank_sr) + solar_system.add_planet(dolly) + solar_system.add_planet(patsy) + solar_system.add_planet(garth) + solar_system.add_planet(johnny) + solar_system.add_planet(reba) + + puts "Country Music Planetary Menu\n" + puts "1. List Planets\n" + puts "2. Planet Information\n" + puts "3. Distance Calculator\n" + puts "4. Exit\n" + + loop do + #prompt to enter selection from above options + case + when input == "1" + puts solar_system.list_planets + when input == "2" + planet = solar_system.get_planet_name + puts planet.summary + when input == "3" + solar_system.add_a_planet + puts "\n...Entered into system. Thank You." + when input == "4" + exit + when input =~ /[[:alpha:]]/ + puts "\nError. Invalid input." end end - end -main \ No newline at end of file +main diff --git a/planet.rb b/planet.rb index d658ccd9..be861672 100644 --- a/planet.rb +++ b/planet.rb @@ -10,17 +10,16 @@ def initialize(name, color, mass, distance, fun_fact, twang_level, likelihood_to @twang_level = twang_level @likelihood_to_be_loved_by_yanks = likelihood_to_be_loved_by_yanks if mass <= 0 - return raise ArgumentError, 'Planet mass must be larger than 0' + return raise ArgumentError, "Planet mass must be larger than 0" end if distance <= 0 - return raise ArgumentError, 'Planet distance must be larger than 0' + return raise ArgumentError, "Planet distance must be larger than 0" end end def summary return "The planet #{@name} is the color #{@color} has a mass of #{@mass} kg, and is #{@distance_from_sun_km} km from the sun. It #{fun_fact}, is know to have a twang level of #{twang_level} out of 5, and is #{likelihood_to_be_loved_by_yanks}% likely - to be loved by out-of-towners visiting the galaxy of Nashville for a bachelor or bachelorette party, never to return again.") -end - + to be loved by out-of-towners visiting the galaxy of Nashville for a bachelor or bachelorette party, never to return again." + end end diff --git a/solar_system.rb b/solar_system.rb index f01a3a8b..9b1f9b81 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -1,5 +1,5 @@ require_relative "planet" -require_relative "solar_system" +require_relative "main" class SolarSystem attr_reader :star_name, :planets From 4d47d7ea56b7bebd2fac27b3c9cdd3e61691ed88 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Wed, 27 Feb 2019 06:38:09 -0800 Subject: [PATCH 17/27] gave loop greeting --- main.rb | 4 ++-- planet.rb | 3 +++ solar_system.rb | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/main.rb b/main.rb index cd24d25d..f776d9f1 100644 --- a/main.rb +++ b/main.rb @@ -10,7 +10,7 @@ def main patsy = Planet.new("Patsy", "chesnut", 70, 40, "enjoys walking after midnight", 3.4, 0.5) garth = Planet.new("Garth", "off-white", 83, 45, "is responsible for the the most insufferable variety of country boi", 4.6, 99) johnny = Planet.new("Johnny", "coal black", 86, 5, "was a campaigner for Native American rights", 3.6, 91) - reba = Planet.new("Reba", "red", 60, "is the only country female solo act to have a No. 1 hit in four straight decades: the 1980s, 90s, 00s and 10s", 5.0, 70) + reba = Planet.new("Reba", "red", 60, "is the only country female solo act to have a No. 1 hit in four straight decades", 5.0, 70) willie = Planet.new("Willie", "old", 70, 7, "ran into a burning house to save his pound of Columbian grass", 3.8, 15) solar_system.add_planet(elvis) @@ -28,7 +28,7 @@ def main puts "4. Exit\n" loop do - #prompt to enter selection from above options + "Please enter your selection from the above options." case when input == "1" puts solar_system.list_planets diff --git a/planet.rb b/planet.rb index be861672..ed84396f 100644 --- a/planet.rb +++ b/planet.rb @@ -1,3 +1,6 @@ +require_relative "main" +require_relative "solar_system" + class Planet attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact, :twang_level, :likelihood_to_be_loved_by_yanks diff --git a/solar_system.rb b/solar_system.rb index 9b1f9b81..e2f4bf49 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -50,7 +50,7 @@ def find_planet_by_name return planet end end - return raise ArgumentError, "Planet not in solar system" + return raise ArgumentError, "Planet does not exist in the Country Music Hall of Planets" end def get_planet_name @@ -72,6 +72,6 @@ def find_distance_between planet1 = get_planet_name planet2 = get_planet_name distance = planet1.distance_from_sun_km - planet2.distance_from_sun_km - puts "\nDistance between #{planet1.name} & #{planet2.name}: #{distance.abs} km." + puts "\nDistance between #{planet1.name} and #{planet2.name}: #{distance.abs} km." end end From 640474d6f9b70ff6481d54f7a624494b3989e960 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Wed, 27 Feb 2019 06:54:21 -0800 Subject: [PATCH 18/27] making tweaks, searching for source of error within spelling or syntax --- main.rb | 10 +++++++--- planet.rb | 2 +- solar_system.rb | 14 +++++++------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/main.rb b/main.rb index f776d9f1..cb22fc32 100644 --- a/main.rb +++ b/main.rb @@ -24,8 +24,9 @@ def main puts "Country Music Planetary Menu\n" puts "1. List Planets\n" puts "2. Planet Information\n" - puts "3. Distance Calculator\n" - puts "4. Exit\n" + puts "3. Add a New Planet\n" + puts "4. Distance Calculator\n" + puts "5. Exit\n" loop do "Please enter your selection from the above options." @@ -39,9 +40,12 @@ def main solar_system.add_a_planet puts "\n...Entered into system. Thank You." when input == "4" + solar_system.find_distance_between + puts "\n...Entered into system. Thank You." + when input == "5" exit when input =~ /[[:alpha:]]/ - puts "\nError. Invalid input." + puts "\nYour response was invalid" end end end diff --git a/planet.rb b/planet.rb index ed84396f..34637bad 100644 --- a/planet.rb +++ b/planet.rb @@ -22,7 +22,7 @@ def initialize(name, color, mass, distance, fun_fact, twang_level, likelihood_to def summary return "The planet #{@name} is the color #{@color} has a mass of #{@mass} kg, and is #{@distance_from_sun_km} km from the sun. - It #{fun_fact}, is know to have a twang level of #{twang_level} out of 5, and is #{likelihood_to_be_loved_by_yanks}% likely + It #{@fun_fact}, is know to have a twang level of #{@twang_level} out of 5, and is #{@likelihood_to_be_loved_by_yanks}% likely to be loved by out-of-towners visiting the galaxy of Nashville for a bachelor or bachelorette party, never to return again." end end diff --git a/solar_system.rb b/solar_system.rb index e2f4bf49..3ab2c68e 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -2,10 +2,10 @@ require_relative "main" class SolarSystem - attr_reader :star_name, :planets + attr_reader :solar_system_name, :planets - def initialize(star_name) - @star_name = star_name + def initialize(solar_system_name) + @solar_system_name = solar_system_name @planets = [] end @@ -14,11 +14,11 @@ def add_planet(planet) end def get_info_new_planet - print "\nEnter new planet name: " + print "\nWhat is your new Planet's name?" planet_name = gets.chomp.to_s - print "\nDescription of #{planet_name}'s color: " + print "\nWhat is #{planet_name}'s color?" color = gets.chomp.to_s - print "\nDistance of planet from #{@star_name}(km): " + print "\nWhat is the distance of planet from #{solar_system_name}(km): " distance = gets.chomp.to_f print "\nMass of #{planet_name}(kg): " mass = gets.chomp.to_f @@ -65,7 +65,7 @@ def get_planet_distance(name) return planet.distance end end - return raise ArgumentError, "Planet not in solar system" + return raise ArgumentError, "Planet does not exist in the Country Music Hall of Planets" end def find_distance_between From c4aa48f0e896a45cc3444a8510b855843794fcea Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Wed, 27 Feb 2019 07:58:57 -0800 Subject: [PATCH 19/27] fixed reba planet to have enough arguments --- main.rb | 2 +- planet.rb | 3 +-- solar_system.rb | 5 ++--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/main.rb b/main.rb index cb22fc32..d549c76c 100644 --- a/main.rb +++ b/main.rb @@ -10,7 +10,7 @@ def main patsy = Planet.new("Patsy", "chesnut", 70, 40, "enjoys walking after midnight", 3.4, 0.5) garth = Planet.new("Garth", "off-white", 83, 45, "is responsible for the the most insufferable variety of country boi", 4.6, 99) johnny = Planet.new("Johnny", "coal black", 86, 5, "was a campaigner for Native American rights", 3.6, 91) - reba = Planet.new("Reba", "red", 60, "is the only country female solo act to have a No. 1 hit in four straight decades", 5.0, 70) + reba = Planet.new("Reba", "red", 60, 10, "is the only country female solo act to have a No. 1 hit in four straight decades", 5.0, 70) willie = Planet.new("Willie", "old", 70, 7, "ran into a burning house to save his pound of Columbian grass", 3.8, 15) solar_system.add_planet(elvis) diff --git a/planet.rb b/planet.rb index 34637bad..7271ec8c 100644 --- a/planet.rb +++ b/planet.rb @@ -1,5 +1,4 @@ -require_relative "main" -require_relative "solar_system" + class Planet attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact, :twang_level, :likelihood_to_be_loved_by_yanks diff --git a/solar_system.rb b/solar_system.rb index 3ab2c68e..0b0ecee4 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -1,5 +1,4 @@ -require_relative "planet" -require_relative "main" + class SolarSystem attr_reader :solar_system_name, :planets @@ -44,7 +43,7 @@ def list_planets return list end - def find_planet_by_name + def find_planet_by_name(planet) @planets.each do |planet| if planet.name == name.capitalize return planet From a10689907ce1ca3006182e48106a7fca220e977c Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Wed, 27 Feb 2019 08:00:33 -0800 Subject: [PATCH 20/27] added line 33 on main to set local variable input --- main.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/main.rb b/main.rb index d549c76c..b3237eec 100644 --- a/main.rb +++ b/main.rb @@ -30,6 +30,7 @@ def main loop do "Please enter your selection from the above options." + input = gets.chomp.to_s case when input == "1" puts solar_system.list_planets From c214304d4e6aa40cbfde3c18938016f1121ddca9 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 12 Mar 2019 08:51:04 -0700 Subject: [PATCH 21/27] fixed error in retrieving planet info --- main.rb | 2 +- solar_system.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/main.rb b/main.rb index b3237eec..36bfa035 100644 --- a/main.rb +++ b/main.rb @@ -38,7 +38,7 @@ def main planet = solar_system.get_planet_name puts planet.summary when input == "3" - solar_system.add_a_planet + solar_system.add_planet puts "\n...Entered into system. Thank You." when input == "4" solar_system.find_distance_between diff --git a/solar_system.rb b/solar_system.rb index 0b0ecee4..1879585b 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -8,8 +8,8 @@ def initialize(solar_system_name) @planets = [] end - def add_planet(planet) - @planets << planet + def add_planet(new_planet) + @planets << new_planet end def get_info_new_planet @@ -43,9 +43,9 @@ def list_planets return list end - def find_planet_by_name(planet) + def find_planet_by_name(planet_name) @planets.each do |planet| - if planet.name == name.capitalize + if planet.name == planet_name.capitalize return planet end end From a96b0f7fbb01a9e3d4395d74ef1aca79bedf0f2a Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 12 Mar 2019 08:54:06 -0700 Subject: [PATCH 22/27] fixed error in creating new planet --- main.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.rb b/main.rb index 36bfa035..86fd337a 100644 --- a/main.rb +++ b/main.rb @@ -38,7 +38,7 @@ def main planet = solar_system.get_planet_name puts planet.summary when input == "3" - solar_system.add_planet + solar_system.get_info_new_planet puts "\n...Entered into system. Thank You." when input == "4" solar_system.find_distance_between From aa35e37e2b2e1f451b57e7749345e1f33e4cd856 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 12 Mar 2019 09:01:00 -0700 Subject: [PATCH 23/27] debugging the distance calculator method, stopping point --- main.rb | 2 +- solar_system.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main.rb b/main.rb index 86fd337a..f3438518 100644 --- a/main.rb +++ b/main.rb @@ -42,7 +42,7 @@ def main puts "\n...Entered into system. Thank You." when input == "4" solar_system.find_distance_between - puts "\n...Entered into system. Thank You." + puts "\nDistance between #{planet1.name} and #{planet2.name}: #{distance.abs} km." when input == "5" exit when input =~ /[[:alpha:]]/ diff --git a/solar_system.rb b/solar_system.rb index 1879585b..3dc299b3 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -67,10 +67,10 @@ def get_planet_distance(name) return raise ArgumentError, "Planet does not exist in the Country Music Hall of Planets" end - def find_distance_between + def find_distance_between(planet1, planet2) planet1 = get_planet_name planet2 = get_planet_name distance = planet1.distance_from_sun_km - planet2.distance_from_sun_km - puts "\nDistance between #{planet1.name} and #{planet2.name}: #{distance.abs} km." + # puts "\nDistance between #{planet1.name} and #{planet2.name}: #{distance.abs} km." end end From aa4ca3fe2b4c5c1c3e42a9cb0b1aa0183dd38f4a Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 12 Mar 2019 09:01:19 -0700 Subject: [PATCH 24/27] saving files helps --- main.rb | 1 - solar_system.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/main.rb b/main.rb index f3438518..248e1945 100644 --- a/main.rb +++ b/main.rb @@ -42,7 +42,6 @@ def main puts "\n...Entered into system. Thank You." when input == "4" solar_system.find_distance_between - puts "\nDistance between #{planet1.name} and #{planet2.name}: #{distance.abs} km." when input == "5" exit when input =~ /[[:alpha:]]/ diff --git a/solar_system.rb b/solar_system.rb index 3dc299b3..0cb4c09f 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -71,6 +71,6 @@ def find_distance_between(planet1, planet2) planet1 = get_planet_name planet2 = get_planet_name distance = planet1.distance_from_sun_km - planet2.distance_from_sun_km - # puts "\nDistance between #{planet1.name} and #{planet2.name}: #{distance.abs} km." + puts "\nDistance between #{planet1.name} and #{planet2.name}: #{distance.abs} km." end end From f625e3b40c29138d0c59b4d202e7247f529a8f02 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 12 Mar 2019 09:35:16 -0700 Subject: [PATCH 25/27] fixed the return raise argument syntax errors --- planet.rb | 6 +++--- solar_system.rb | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/planet.rb b/planet.rb index 7271ec8c..53ac54fe 100644 --- a/planet.rb +++ b/planet.rb @@ -12,15 +12,15 @@ def initialize(name, color, mass, distance, fun_fact, twang_level, likelihood_to @twang_level = twang_level @likelihood_to_be_loved_by_yanks = likelihood_to_be_loved_by_yanks if mass <= 0 - return raise ArgumentError, "Planet mass must be larger than 0" + raise ArgumentError, "Planet mass must be larger than 0" end if distance <= 0 - return raise ArgumentError, "Planet distance must be larger than 0" + raise ArgumentError, "Planet distance must be larger than 0" end end def summary - return "The planet #{@name} is the color #{@color} has a mass of #{@mass} kg, and is #{@distance_from_sun_km} km from the sun. + puts "The planet #{@name} is the color #{@color} has a mass of #{@mass} kg, and is #{@distance_from_sun_km} km from the sun. It #{@fun_fact}, is know to have a twang level of #{@twang_level} out of 5, and is #{@likelihood_to_be_loved_by_yanks}% likely to be loved by out-of-towners visiting the galaxy of Nashville for a bachelor or bachelorette party, never to return again." end diff --git a/solar_system.rb b/solar_system.rb index 0cb4c09f..0b66b31f 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -49,7 +49,7 @@ def find_planet_by_name(planet_name) return planet end end - return raise ArgumentError, "Planet does not exist in the Country Music Hall of Planets" + raise ArgumentError, "Planet does not exist in the Country Music Hall of Planets" end def get_planet_name @@ -64,13 +64,13 @@ def get_planet_distance(name) return planet.distance end end - return raise ArgumentError, "Planet does not exist in the Country Music Hall of Planets" + raise ArgumentError, "Planet does not exist in the Country Music Hall of Planets" end - def find_distance_between(planet1, planet2) + def find_distance_between planet1 = get_planet_name planet2 = get_planet_name - distance = planet1.distance_from_sun_km - planet2.distance_from_sun_km + distance = (planet1.distance_from_sun_km) - (planet2.distance_from_sun_km) puts "\nDistance between #{planet1.name} and #{planet2.name}: #{distance.abs} km." end end From c884b3c469c84ad83e8d375bb0580c9de0d2e78c Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 12 Mar 2019 09:46:44 -0700 Subject: [PATCH 26/27] removed awkward variable --- main.rb | 16 ++++++++-------- planet.rb | 6 ++---- solar_system.rb | 4 +--- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/main.rb b/main.rb index 248e1945..3e5dc16a 100644 --- a/main.rb +++ b/main.rb @@ -4,14 +4,14 @@ def main solar_system = SolarSystem.new("Sol") - elvis = Planet.new("Elvis", "shiny", 159, 20, "recorded more than 600 songs, but did not write any of them", 3.5, 85) - hank_sr = Planet.new("Hank Sr", "white as hell", 72, 30, "recorded 14 songs as his alter ego, Luke the Drifter", 4.5, 10) - dolly = Planet.new("Dolly", "canary yellow", 52, 18, "once entered a Dolly look-alike drag queen contest and lost", 4.8, 90) - patsy = Planet.new("Patsy", "chesnut", 70, 40, "enjoys walking after midnight", 3.4, 0.5) - garth = Planet.new("Garth", "off-white", 83, 45, "is responsible for the the most insufferable variety of country boi", 4.6, 99) - johnny = Planet.new("Johnny", "coal black", 86, 5, "was a campaigner for Native American rights", 3.6, 91) - reba = Planet.new("Reba", "red", 60, 10, "is the only country female solo act to have a No. 1 hit in four straight decades", 5.0, 70) - willie = Planet.new("Willie", "old", 70, 7, "ran into a burning house to save his pound of Columbian grass", 3.8, 15) + elvis = Planet.new("Elvis", "shiny", 159, 20, "recorded more than 600 songs, but did not write any of them", 3.5) + hank_sr = Planet.new("Hank Sr", "white as hell", 72, 30, "recorded 14 songs as his alter ego, Luke the Drifter", 4.5) + dolly = Planet.new("Dolly", "canary yellow", 52, 18, "once entered a Dolly look-alike drag queen contest and lost", 4.8) + patsy = Planet.new("Patsy", "chesnut", 70, 40, "enjoys walking after midnight", 3.4) + garth = Planet.new("Garth", "off-white", 83, 45, "is responsible for the the most insufferable variety of country boi", 4.6) + johnny = Planet.new("Johnny", "coal black", 86, 5, "was a campaigner for Native American rights", 3.6) + reba = Planet.new("Reba", "red", 60, 10, "is the only country female solo act to have a No. 1 hit in four straight decades", 5.0) + willie = Planet.new("Willie", "old", 70, 7, "ran into a burning house to save his pound of Columbian grass", 3.8) solar_system.add_planet(elvis) solar_system.add_planet(hank_sr) diff --git a/planet.rb b/planet.rb index 53ac54fe..75c0b354 100644 --- a/planet.rb +++ b/planet.rb @@ -3,14 +3,13 @@ class Planet attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact, :twang_level, :likelihood_to_be_loved_by_yanks - def initialize(name, color, mass, distance, fun_fact, twang_level, likelihood_to_be_loved_by_yanks) + def initialize(name, color, mass, distance, fun_fact, twang_level) @name = name.capitalize @color = color @mass_kg = mass_kg @distance_from_sun_km = distance_from_sun_km @fun_fact = fun_fact @twang_level = twang_level - @likelihood_to_be_loved_by_yanks = likelihood_to_be_loved_by_yanks if mass <= 0 raise ArgumentError, "Planet mass must be larger than 0" end @@ -21,7 +20,6 @@ def initialize(name, color, mass, distance, fun_fact, twang_level, likelihood_to def summary puts "The planet #{@name} is the color #{@color} has a mass of #{@mass} kg, and is #{@distance_from_sun_km} km from the sun. - It #{@fun_fact}, is know to have a twang level of #{@twang_level} out of 5, and is #{@likelihood_to_be_loved_by_yanks}% likely - to be loved by out-of-towners visiting the galaxy of Nashville for a bachelor or bachelorette party, never to return again." + It #{@fun_fact}, and is know to have a twang level of #{@twang_level} out of 5." end end diff --git a/solar_system.rb b/solar_system.rb index 0b66b31f..7042d3bb 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -25,10 +25,8 @@ def get_info_new_planet fun_fact = gets.chomp.to_s print "\nPlease rate the planet's twang on a scale of 0-5.0 #{planet_name}: " twang_level = gets.chomp.to_f - print "\nPlease rate the planet's likelihood to be beloved in New England, on a scale of 0-100 #{planet_name}: " - likelihood_to_be_loved_by_yanks = gets.chomp.to_s - new_planet = Planet.new(planet_name, color, distance, mass, fun_fact, twang_level, likelihood_to_be_loved_by_yanks) + new_planet = Planet.new(planet_name, color, distance, mass, fun_fact, twang_level) add_planet(new_planet) print "\nGenerating new data" From ef5a972bbecb7d09b9c6570f882f658d4690ff8f Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 12 Mar 2019 10:25:30 -0700 Subject: [PATCH 27/27] fixed distance_between error --- planet.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/planet.rb b/planet.rb index 75c0b354..6743b879 100644 --- a/planet.rb +++ b/planet.rb @@ -3,7 +3,7 @@ class Planet attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact, :twang_level, :likelihood_to_be_loved_by_yanks - def initialize(name, color, mass, distance, fun_fact, twang_level) + def initialize(name, color, mass, distance_from_sun_km, fun_fact, twang_level) @name = name.capitalize @color = color @mass_kg = mass_kg @@ -13,7 +13,7 @@ def initialize(name, color, mass, distance, fun_fact, twang_level) if mass <= 0 raise ArgumentError, "Planet mass must be larger than 0" end - if distance <= 0 + if distance_from_sun_km <= 0 raise ArgumentError, "Planet distance must be larger than 0" end end