From 05103a605178c0b806871253355fcc14a002eaa4 Mon Sep 17 00:00:00 2001 From: Maria Wissler Date: Tue, 26 Feb 2019 20:27:02 -0800 Subject: [PATCH 1/5] Wave 1 --- main.rb | 12 ++++++++++++ planet.rb | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 main.rb create mode 100644 planet.rb diff --git a/main.rb b/main.rb new file mode 100644 index 00000000..8aea1908 --- /dev/null +++ b/main.rb @@ -0,0 +1,12 @@ +# main.rb +require_relative 'Planet' + +def main + earth = Planet.new('earth', 'blue-green', '5.972e24', '1.496e8', 'only planet known to support life') + puts earth.summary + mars = Planet.new('mars', 'reddish-brown','‎0.64171','141.6 million mi','it has the longest rotation period, rotates in the opposite direction to most other planets') + puts mars.summary + +end + +main diff --git a/planet.rb b/planet.rb new file mode 100644 index 00000000..21dfb7b2 --- /dev/null +++ b/planet.rb @@ -0,0 +1,17 @@ + +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 "#{@name.capitalize}, has a #{color} color, with a mass of #{mass_kg}, holding a distance from the sun of #{distance_from_sun_km}, a fun fact is: #{fun_fact}" + end + +end From 8f2f393801cab881e82fdab0f96e4299fb2c7d3d Mon Sep 17 00:00:00 2001 From: Maria Wissler Date: Tue, 26 Feb 2019 23:24:05 -0800 Subject: [PATCH 2/5] main wave-1 --- main.rb | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/main.rb b/main.rb index 8aea1908..59f9666b 100644 --- a/main.rb +++ b/main.rb @@ -1,12 +1,25 @@ # main.rb -require_relative 'Planet' +require_relative 'planet' +require_relative 'solar_system' def main + solar_system = SolarSystem.new('Sol') + earth = Planet.new('earth', 'blue-green', '5.972e24', '1.496e8', 'only planet known to support life') - puts earth.summary + solar_system.add_planet(earth) mars = Planet.new('mars', 'reddish-brown','‎0.64171','141.6 million mi','it has the longest rotation period, rotates in the opposite direction to most other planets') - puts mars.summary - + solar_system.add_planet(mars) + jupiter = Planet.new('jupiter','orange with white bands','1,898.19','483.8 million mi','the largest in the Solar System') + solar_system.add_planet(jupiter) + saturn = Planet.new('saturn','pale-gold','5.9724','890.8 million mi','second-largest in the Solar System. It is a gas giant a radius nine times that of Earth') + solar_system.add_planet(saturn) + + list = solar_system.list_planets + puts list + + found_planet = solar_system.find_planet_by_name("earth") + puts found_planet.summary + end main From 9c483593c6bd98252c231a5b41ea37e9f88fb161 Mon Sep 17 00:00:00 2001 From: Maria Wissler Date: Tue, 26 Feb 2019 23:26:29 -0800 Subject: [PATCH 3/5] solar system-wave 2 --- solar_system.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 solar_system.rb diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..16d6d259 --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,38 @@ +# Solar System +class SolarSystem + attr_reader :star_name, :planets + + def initialize(star_name) + @star_name = star_name + @planets = [] + end + + def add_planet(planet) + @planets << planet + end + + def list_planets + i = 0 + list = [] + @planets.each do |planet| + list << "#{i += 1}. #{planet.name}" + end + puts "Planets orbiting #{star_name}:" + return list + end + + def find_planet_by_name(name) + @planets.each do |planet| + if planet.name.downcase == name.downcase + return planet + end + end + end + +end + + + + + + From d10e73c60e9447a2946c6f359c8c8163babc96ec Mon Sep 17 00:00:00 2001 From: Maria Wissler Date: Wed, 27 Feb 2019 00:53:28 -0800 Subject: [PATCH 4/5] main wave 3 --- main.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/main.rb b/main.rb index 59f9666b..b9171a71 100644 --- a/main.rb +++ b/main.rb @@ -20,6 +20,27 @@ def main found_planet = solar_system.find_planet_by_name("earth") puts found_planet.summary + options = [ "list planets", "get planet details", "add a planet", "exit"] + + puts "What would you like to do, please choose from the following options:" + puts options + user_input = gets.chomp.downcase + + while options.include? user_input + case user_input + when "list planets" + puts solar_system.list_planets + when "get planet details" + puts solar_system.planet_details.summary + when "add a planet" + puts solar_system.new_planet + when "exit" + exit +end + + puts "What would you like to do next?" + user_input = gets.chomp.downcase +end end main From 75831caefa5efbce0790b240a541419838984c25 Mon Sep 17 00:00:00 2001 From: Maria Wissler Date: Wed, 27 Feb 2019 00:53:59 -0800 Subject: [PATCH 5/5] solar system wave 3 --- solar_system.rb | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/solar_system.rb b/solar_system.rb index 16d6d259..37db1a37 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -23,16 +23,50 @@ def list_planets def find_planet_by_name(name) @planets.each do |planet| - if planet.name.downcase == name.downcase + if planet.name == name.downcase return planet - end + elsif planet.name != name.downcase + puts "no related data found, please enter a listed planet" + planet_details + end end end + def planet_details + puts "Enter the planet you want a little more info of" + user_input = gets.chomp.downcase + + planet_info = find_planet_by_name(user_input) + return planet_info + end + + def new_planet + puts "We will need the following planet information:" + + puts "Planet name:" + name = gets.chomp.downcase + + puts "Planet color:" + color = gets.chomp.downcase + + puts "Planet Mass:" + mass = gets.chomp.to_i + + puts "Planet Distance from the Sun:" + distance_from_sun = gets.chomp + + puts "Planet Fun Fact:" + fun_fact = gets.chomp_to_i + + new_planet = Planet.new(name, color, mass, distance_from_sun, fun_fact) + add_planet(new_planet) + + end end +