From 8d2bd06b2157f8c5cb92f3cbf72921f95c8cf7aa Mon Sep 17 00:00:00 2001 From: Yesenia Date: Tue, 18 Feb 2020 15:39:26 -0800 Subject: [PATCH 1/3] Complete Wave 1 requirements. --- main.rb | 18 ++++++++++++++++++ planet.rb | 24 ++++++++++++++++++++++++ 2 files changed, 42 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..7c91cd64 --- /dev/null +++ b/main.rb @@ -0,0 +1,18 @@ +# main.rb + +require_relative 'planet' + +def main + + # Instance of Planet 1 + venus = Planet.new('Venus', 'yellowish', 108212290.56, 4.867e+24, 'Lady Gaga has an absolute banger on her Artpop album also titled "Venus".') + + puts venus.summary + + # Instance of Planet 2 + neptune = Planet.new('Neptune', 'blue', 2781900000, 1.024e+26, 'its cold and scary.') + + puts neptune.summary +end + +main # invoke main \ No newline at end of file diff --git a/planet.rb b/planet.rb new file mode 100644 index 00000000..0912cddb --- /dev/null +++ b/planet.rb @@ -0,0 +1,24 @@ +# planet.rb + +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 "So you want to know more about #{@name}? Sure! Here are some basics:" + + "\n" + " 1. It is the color #{@color}." + + "\n" + " 2. It weighs #{@mass_kg} kg." + + "\n" + " 3. It is #{@distance_from_sun_km } kilometers from the sun." + + "\n" + " 4. And fun fact: #{@fun_fact}" + + "\n" + "That's about all I know!" + end + +end \ No newline at end of file From be8d6bce39c9f25a79a67f2ee7b221629ef389c4 Mon Sep 17 00:00:00 2001 From: Yesenia Date: Tue, 18 Feb 2020 17:46:51 -0800 Subject: [PATCH 2/3] Completed Wave 2 Requirements. --- main.rb | 24 ++++++++++++++++++------ planet.rb | 5 ++--- solar-system.rb | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 solar-system.rb diff --git a/main.rb b/main.rb index 7c91cd64..8d0233df 100644 --- a/main.rb +++ b/main.rb @@ -1,18 +1,30 @@ # main.rb require_relative 'planet' +require_relative 'solar-system' def main - # Instance of Planet 1 - venus = Planet.new('Venus', 'yellowish', 108212290.56, 4.867e+24, 'Lady Gaga has an absolute banger on her Artpop album also titled "Venus".') - - puts venus.summary + # Create Instance of Solar System + solar_system = SolarSystem.new('Sun') - # Instance of Planet 2 + # Create Instances of Planets neptune = Planet.new('Neptune', 'blue', 2781900000, 1.024e+26, 'its cold and scary.') + venus = Planet.new('Venus', 'yellowish', 108212290.56, 4.867e+24, 'Lady Gaga has an absolute banger on her Artpop album also titled "Venus".') + + # Add planets to solar system + solar_system.add_planet(neptune) + solar_system.add_planet(venus) + + # Display list + list = solar_system.list_planets + puts list + + # Find matching planet name + found_planet = solar_system.find_planet_by_name('VENuS') + puts found_planet + puts found_planet.summary - puts neptune.summary end main # invoke main \ No newline at end of file diff --git a/planet.rb b/planet.rb index 0912cddb..f70292e6 100644 --- a/planet.rb +++ b/planet.rb @@ -13,12 +13,11 @@ def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact) end def summary - return "So you want to know more about #{@name}? Sure! Here are some basics:" + + return "Here are some basics on #{@name}:" + "\n" + " 1. It is the color #{@color}." + "\n" + " 2. It weighs #{@mass_kg} kg." + "\n" + " 3. It is #{@distance_from_sun_km } kilometers from the sun." + - "\n" + " 4. And fun fact: #{@fun_fact}" + - "\n" + "That's about all I know!" + "\n" + " 4. And fun fact: #{@fun_fact}" end end \ No newline at end of file diff --git a/solar-system.rb b/solar-system.rb new file mode 100644 index 00000000..4b1204e5 --- /dev/null +++ b/solar-system.rb @@ -0,0 +1,35 @@ +# solar-system.rb + +class SolarSystem + + attr_reader :star_name, :planets + + def initialize(star_name) + @star_name = star_name + @planets = [] + end + + def add_planet(new_planet) + @planets << new_planet + end + + def list_planets + str = "Planets orbiting #{@star_name}" + @planets.each_with_index do |planet, i| + str.concat("\n #{i+1}. #{planet.name}") + end + return str + end + + def find_planet_by_name(name) + formatted_name = name.downcase.capitalize # doing this means that every newly instantiated planet name must be recorded in this case format: "Name" + match = "" + @planets.each do |planet| + if formatted_name == planet.name + match = planet + end + end + return match + end + +end \ No newline at end of file From 5af8b3ddae7b81fd67becd064f4e38fc42aa1b87 Mon Sep 17 00:00:00 2001 From: Yesenia Date: Thu, 20 Feb 2020 09:24:24 -0800 Subject: [PATCH 3/3] Completed wave 3 requirements. --- main.rb | 62 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/main.rb b/main.rb index 8d0233df..00f8f36b 100644 --- a/main.rb +++ b/main.rb @@ -3,27 +3,67 @@ require_relative 'planet' require_relative 'solar-system' +def add_planet_info() + print "What is the name of the planet you'd like to add? " + planet_name = gets.chomp.downcase.capitalize + + print "What is the planet's color? " + planet_color = gets.chomp.downcase.capitalize + print "How much does this planet weigh, in kg? " + planet_weight = gets.chomp.downcase + print "How far is this planet from the sun, in km? " + planet_distance = gets.chomp.downcase + print "What is a fun fact about this planet? " + planet_fun_fact = gets.chomp.downcase + new_planet = Planet.new(planet_name, planet_color, planet_weight, planet_distance, planet_fun_fact) + return new_planet +end + def main # Create Instance of Solar System solar_system = SolarSystem.new('Sun') # Create Instances of Planets - neptune = Planet.new('Neptune', 'blue', 2781900000, 1.024e+26, 'its cold and scary.') venus = Planet.new('Venus', 'yellowish', 108212290.56, 4.867e+24, 'Lady Gaga has an absolute banger on her Artpop album also titled "Venus".') - + earth = Planet.new('Earth', 'blue-green', 5.972e24, 1.496e8, 'Only planet known to support life.') + neptune = Planet.new('Neptune', 'blue', 2781900000, 1.024e+26, 'its cold and scary.') + # Add planets to solar system - solar_system.add_planet(neptune) solar_system.add_planet(venus) + solar_system.add_planet(earth) + solar_system.add_planet(neptune) + + puts + puts "Welcome to the Solar System Program! You have four options: " + puts " 1. If you would like to know which planets are currently in this system, please type 'list planets'" + puts " 2. If you would like to learn about a specific planet in this system, please type 'planet info'" + puts " 3. If you want to add a planet to this system, please type 'add planet'" + puts " 4. Or if you would like to quit this program, please type 'exit'" + print "Which option would you like? " + option = gets.chomp.downcase + - # Display list - list = solar_system.list_planets - puts list - - # Find matching planet name - found_planet = solar_system.find_planet_by_name('VENuS') - puts found_planet - puts found_planet.summary + case (option) + + when "list planets" + puts solar_system.list_planets + + when "planet info" + print "What is the name of the planet you'd like to know more about? " + planet_choice = gets.chomp.downcase + found_planet = solar_system.find_planet_by_name(planet_choice) + puts found_planet.summary + + when "add planet" + new_planet = add_planet_info() + solar_system.add_planet(new_planet) + puts "Cool! thanks for adding #{new_planet.name}. The updated planet list now looks like this: " + "\n" + "#{solar_system.list_planets}" + + when "exit" + puts "Okay, bye!" + + end end