From 1ab54b6713cd73be18788dc96229fba35467397f Mon Sep 17 00:00:00 2001 From: Ngoc Le Date: Tue, 26 Feb 2019 13:01:54 -0800 Subject: [PATCH 1/9] Created planet.rb, solar_system.rb, and main.rb to display name of planet -Wave 2 completed requirement 4 --- lib/.DS_Store | Bin 0 -> 6148 bytes lib/main.rb | 18 ++++++++++++++++++ lib/planet.rb | 22 ++++++++++++++++++++++ lib/solar_system.rb | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 lib/.DS_Store create mode 100644 lib/main.rb create mode 100644 lib/planet.rb create mode 100644 lib/solar_system.rb diff --git a/lib/.DS_Store b/lib/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..28233d6d15f9bf5c9ac5cf883e9ccc3d05bff129 GIT binary patch literal 6148 zcmeHKyG{c!5S)cb1W}L_v?&M_X)NGc6TJ z1yX@jAQkvI1$btwjSn2NO$AbcRNzwq-5&~Fu?ZX;ZR=oTB>-{6ZZpPuX;w}NYyt;I zj?l!ZM5juW7~*vHm&j`Z2S=wvqWF+l`J;FdTb=V4ONTU$*`@-iz@`FP`_d+Q{$KEy zsTTQ`l1(a*3j9|EWHh^)P5E_kwto9gJ!=d7hOVZ0g9bFl8 Date: Tue, 26 Feb 2019 13:04:32 -0800 Subject: [PATCH 2/9] Revert "Created planet.rb, solar_system.rb, and main.rb to display name of planet -Wave 2 completed requirement 4" This reverts commit 1ab54b6713cd73be18788dc96229fba35467397f. --- lib/.DS_Store | Bin 6148 -> 0 bytes lib/main.rb | 18 ------------------ lib/planet.rb | 22 ---------------------- lib/solar_system.rb | 37 ------------------------------------- 4 files changed, 77 deletions(-) delete mode 100644 lib/.DS_Store delete mode 100644 lib/main.rb delete mode 100644 lib/planet.rb delete mode 100644 lib/solar_system.rb diff --git a/lib/.DS_Store b/lib/.DS_Store deleted file mode 100644 index 28233d6d15f9bf5c9ac5cf883e9ccc3d05bff129..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKyG{c!5S)cb1W}L_v?&M_X)NGc6TJ z1yX@jAQkvI1$btwjSn2NO$AbcRNzwq-5&~Fu?ZX;ZR=oTB>-{6ZZpPuX;w}NYyt;I zj?l!ZM5juW7~*vHm&j`Z2S=wvqWF+l`J;FdTb=V4ONTU$*`@-iz@`FP`_d+Q{$KEy zsTTQ`l1(a*3j9|EWHh^)P5E_kwto9gJ!=d7hOVZ0g9bFl8 Date: Tue, 26 Feb 2019 13:09:34 -0800 Subject: [PATCH 3/9] Created planet.rb, solar_system.rb, and main.rb to output a listing of planet instances --- lib/main.rb | 18 ++++++++++++++++++ lib/planet.rb | 22 ++++++++++++++++++++++ lib/solar_system.rb | 28 ++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 lib/main.rb create mode 100644 lib/planet.rb create mode 100644 lib/solar_system.rb diff --git a/lib/main.rb b/lib/main.rb new file mode 100644 index 00000000..bb62353f --- /dev/null +++ b/lib/main.rb @@ -0,0 +1,18 @@ +require_relative "planet.rb" +require_relative "solar_system.rb" + +def main + solar_system = SolarSystem.new("Sun") + + mercury = Planet.new("Mercury", "dark grey", 4.867e24, 5.791e7, "Mercury is the smallest plannet in our solar system") + solar_system.add_planet(mercury) + + saturn = Planet.new("Saturn", "yellowish-brown", 5.683e26, 1.434e9, "Saturn is the second largest planet in our solar system") + solar_system.add_planet(saturn) + + list = solar_system.list_planets + + puts list +end + +main diff --git a/lib/planet.rb b/lib/planet.rb new file mode 100644 index 00000000..97b918f6 --- /dev/null +++ b/lib/planet.rb @@ -0,0 +1,22 @@ +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 + + def summary + return "Planet #{name} has the color of #{color} with the mass of #{mass_kg} kgs. This planet is #{distance_from_sun_km} km from the sun. A fun-fact about this planet is: #{fun_fact}" + end +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" diff --git a/lib/solar_system.rb b/lib/solar_system.rb new file mode 100644 index 00000000..9d65d83b --- /dev/null +++ b/lib/solar_system.rb @@ -0,0 +1,28 @@ + +class SolarSystem + attr_reader :star_name, :planet + + def initialize(star_name) + @star_name = star_name + @planets = [] + end + + def add_planet(planet_instance) + @planets << planet_instance + end + + def list_planets + conclusion_statement = "Planets orbiting #{star_name}:\n" + + i = 1 + planet_list = "" + @planets.each do |planet| + planet_list += "#{i}.#{planet.name} \n" + i += 1 + end + + return conclusion_statement + planet_list + end +end + +# earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") From 741a1057259cbfb46334cbfb0c46f64c2e314db6 Mon Sep 17 00:00:00 2001 From: Ngoc Le Date: Tue, 26 Feb 2019 13:14:00 -0800 Subject: [PATCH 4/9] Added test to check if a new instance is an instance of the class Planet --- specs/planet_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 specs/planet_spec.rb diff --git a/specs/planet_spec.rb b/specs/planet_spec.rb new file mode 100644 index 00000000..dbc3307d --- /dev/null +++ b/specs/planet_spec.rb @@ -0,0 +1,11 @@ +require "minitest/autorun" +require "minitest/reporters" +require_relative "../lib/planet.rb" +Minitest::Reporters.use! + +describe "planet" do + it "Check if a new instance is an instance of class Planet " do + earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") + expect(earth).must_be_instance_of Planet + end +end From d75510ba50792cff405c44dcbeda7973e9f25146 Mon Sep 17 00:00:00 2001 From: Ngoc Le Date: Tue, 26 Feb 2019 13:26:24 -0800 Subject: [PATCH 5/9] updated main.rb and solar_system.rb to return the summary of an instance of a planet --- lib/main.rb | 7 +++++++ lib/solar_system.rb | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/main.rb b/lib/main.rb index bb62353f..93096dc2 100644 --- a/lib/main.rb +++ b/lib/main.rb @@ -10,9 +10,16 @@ def main saturn = Planet.new("Saturn", "yellowish-brown", 5.683e26, 1.434e9, "Saturn is the second largest planet in our solar system") solar_system.add_planet(saturn) + earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") + solar_system.add_planet(earth) + list = solar_system.list_planets puts list + + found_planet = solar_system.find_planet_by_name("sATURN") + puts found_planet + puts found_planet.summary end main diff --git a/lib/solar_system.rb b/lib/solar_system.rb index 9d65d83b..da50f2f2 100644 --- a/lib/solar_system.rb +++ b/lib/solar_system.rb @@ -23,6 +23,8 @@ def list_planets return conclusion_statement + planet_list end -end -# earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") + def find_planet_by_name(planet_name) + @planets.find { |planet| planet.name.downcase == planet_name.downcase } + end +end From c4fc0d74f6b8e04dc1105298bacc6bfe6a6f9ee8 Mon Sep 17 00:00:00 2001 From: Ngoc Le Date: Tue, 26 Feb 2019 13:43:44 -0800 Subject: [PATCH 6/9] Create loop to prompt user inputs 'list planets or exit' --- lib/main.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/main.rb b/lib/main.rb index 93096dc2..ace10dfa 100644 --- a/lib/main.rb +++ b/lib/main.rb @@ -22,4 +22,12 @@ def main puts found_planet.summary end -main +puts "Welcome to Solar System program!" +puts "Please enter 'list planets' if you would like to see facts about planets. Enter 'exit' to exit the program" +user_input = gets.chomp + +until user_input.downcase == "exit" + main + puts "Please enter 'list planets' if you would like to see facts about planets. Enter 'exit' to exit the program" + user_input = gets.chomp +end From ca70ac2845d2b3a2ac5b65045a2f3116c52f3f9c Mon Sep 17 00:00:00 2001 From: Ngoc Le Date: Wed, 27 Feb 2019 00:09:02 -0800 Subject: [PATCH 7/9] Added plant details option -part 2 of wave 3 and add planet option - part 3 of wave 3 --- lib/main.rb | 50 ++++++++++++++++++++++++++++++--------------- lib/solar_system.rb | 17 +++++++++++++++ 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/lib/main.rb b/lib/main.rb index ace10dfa..ec5afd46 100644 --- a/lib/main.rb +++ b/lib/main.rb @@ -2,32 +2,50 @@ require_relative "solar_system.rb" def main + + #Added planets' info to each planet instance solar_system = SolarSystem.new("Sun") + earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") + solar_system.add_planet(earth) + mercury = Planet.new("Mercury", "dark grey", 4.867e24, 5.791e7, "Mercury is the smallest plannet in our solar system") solar_system.add_planet(mercury) + neptune = Planet.new("Neptune", "purple", 1.024e26, 4.495e9, "It is four times wider than Earth") + solar_system.add_planet(neptune) + saturn = Planet.new("Saturn", "yellowish-brown", 5.683e26, 1.434e9, "Saturn is the second largest planet in our solar system") solar_system.add_planet(saturn) - earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") - solar_system.add_planet(earth) + venus = Planet.new("Venus", "opal", 4.867e24, 1.082e8, "It has intense heat and volcanic activity") + solar_system.add_planet(venus) - list = solar_system.list_planets + ######## Prompt User's inputs######## - puts list + puts "Welcome to Solar System program!" + puts "What would you like to do?" + puts "[list planets] [planet details] [add planet] [exit]" + user_input = gets.chomp - found_planet = solar_system.find_planet_by_name("sATURN") - puts found_planet - puts found_planet.summary + until user_input.downcase == "exit" + case user_input.downcase + when "list planets" + puts solar_system.list_planets + when "planet details" + puts "Which planet would you like to learn about?" + planet_details_input = gets.chomp + found_planet = solar_system.find_planet_by_name(planet_details_input.downcase) + puts found_planet.summary + when "add planet" + solar_system.user_added_planet + puts solar_system.list_planets + end + + puts "What would you like to do next?" + puts "[list planets] [planet details] [add planet] [exit]" + user_input = gets.chomp + end end -puts "Welcome to Solar System program!" -puts "Please enter 'list planets' if you would like to see facts about planets. Enter 'exit' to exit the program" -user_input = gets.chomp - -until user_input.downcase == "exit" - main - puts "Please enter 'list planets' if you would like to see facts about planets. Enter 'exit' to exit the program" - user_input = gets.chomp -end +main diff --git a/lib/solar_system.rb b/lib/solar_system.rb index da50f2f2..fc926706 100644 --- a/lib/solar_system.rb +++ b/lib/solar_system.rb @@ -27,4 +27,21 @@ def list_planets def find_planet_by_name(planet_name) @planets.find { |planet| planet.name.downcase == planet_name.downcase } end + + def user_added_planet + puts "Please enter new planet's name" + planet_name = gets.chomp + puts "Please enter new planet's color" + planet_color = gets.chomp + puts "Please enter new planet's mass in kilograms" + planet_mass = gets.chomp + puts "Please enter the distance between this new planet and the sun" + planet_distance = gets.chomp + puts "Please enter new planet's fun_fact" + fun_fact = gets.chomp + + user_planet = Planet.new(planet_name.capitalize, planet_color, planet_mass, planet_distance, fun_fact) + + add_planet(user_planet) + end end From a33b964af6c7a9841097501d11881d761344d991 Mon Sep 17 00:00:00 2001 From: Ngoc Le Date: Wed, 27 Feb 2019 00:31:46 -0800 Subject: [PATCH 8/9] minor format changes --- lib/solar_system.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/solar_system.rb b/lib/solar_system.rb index fc926706..a863f718 100644 --- a/lib/solar_system.rb +++ b/lib/solar_system.rb @@ -34,9 +34,9 @@ def user_added_planet puts "Please enter new planet's color" planet_color = gets.chomp puts "Please enter new planet's mass in kilograms" - planet_mass = gets.chomp + planet_mass = gets.chomp.to_i puts "Please enter the distance between this new planet and the sun" - planet_distance = gets.chomp + planet_distance = gets.chomp.to_i puts "Please enter new planet's fun_fact" fun_fact = gets.chomp From 153c93fbe9b4d5ca075f92c6a4ec608ec192d273 Mon Sep 17 00:00:00 2001 From: lebaongoc <37170363+lebaongoc@users.noreply.github.com> Date: Wed, 27 Feb 2019 14:14:50 -0800 Subject: [PATCH 9/9] Update planet.rb --- lib/planet.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/planet.rb b/lib/planet.rb index 97b918f6..72415dff 100644 --- a/lib/planet.rb +++ b/lib/planet.rb @@ -13,10 +13,3 @@ def summary return "Planet #{name} has the color of #{color} with the mass of #{mass_kg} kgs. This planet is #{distance_from_sun_km} km from the sun. A fun-fact about this planet is: #{fun_fact}" end 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"