From 32b3a6463022a4c07b9ef289463f7a382013005a Mon Sep 17 00:00:00 2001 From: Dominique Date: Mon, 19 Aug 2019 16:49:52 -0700 Subject: [PATCH 1/3] Wave 1 complete main.rb --- main.rb | 13 +++++++++++++ planet.rb | 16 ++++++++++++++++ solar_system.rb | 5 +++++ 3 files changed, 34 insertions(+) create mode 100644 main.rb create mode 100644 planet.rb create mode 100644 solar_system.rb diff --git a/main.rb b/main.rb new file mode 100644 index 00000000..6606d742 --- /dev/null +++ b/main.rb @@ -0,0 +1,13 @@ +require_relative "planet" + +#Wave 2 +def main + jupiter = Planet.new("Jupiter", "Orange", "5.972e23", "1.94e8", "Has a red eye full of storms") + earth = Planet.new("Earth", "Blue", "34.e39", "14", "Only planet with life") + + + puts jupiter.summary +end + +main + diff --git a/planet.rb b/planet.rb new file mode 100644 index 00000000..696b1f3f --- /dev/null +++ b/planet.rb @@ -0,0 +1,16 @@ +class Planet + #Wave 1 + def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact) + @name = name + @color = color + @mass_kg = mass_kg + @distance = distance_from_sun_km + @fun_fact = fun_fact + end + + attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact + + def summary + return "Planet #{@name} is #{@color} and #{@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..33638f27 --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,5 @@ + +# Wave 2 + + + From 4081ed30bc6a1c96558b84ecda9257773a3aecad Mon Sep 17 00:00:00 2001 From: Dominique Date: Tue, 20 Aug 2019 16:59:37 -0700 Subject: [PATCH 2/3] Wave 2 completed main.rb --- main.rb | 22 ++++++++++++++++++++-- planet.rb | 2 +- solar_system.rb | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/main.rb b/main.rb index 6606d742..3fb6a57d 100644 --- a/main.rb +++ b/main.rb @@ -1,12 +1,30 @@ +# Wave 1 require_relative "planet" +require_relative "solar_system" -#Wave 2 def main jupiter = Planet.new("Jupiter", "Orange", "5.972e23", "1.94e8", "Has a red eye full of storms") earth = Planet.new("Earth", "Blue", "34.e39", "14", "Only planet with life") + mercury = Planet.new("Mercury", "Red", "35.e39", "10", "Hottest Planet") + venus = Planet.new("Venus", "Brown", "39.e39", "20", "2nd Hottest Planet") + mars = Planet.new("Mars", "Brown-Orange", "40.e27", "30", "Super Rocky") + + puts earth.summary + + # Wave 2 + solar_system = SolarSystem.new("Sun") + solar_system.add_planet(mercury) + solar_system.add_planet(venus) + solar_system.add_planet(earth) + solar_system.add_planet(mars) + solar_system.add_planet(jupiter) + list = solar_system.list_planets + puts list - puts jupiter.summary + found_planet = solar_system.find_planet_by_name("eArTh") + puts "\n#{found_planet}" + puts "\n#{found_planet.summary}" end main diff --git a/planet.rb b/planet.rb index 696b1f3f..3951a06c 100644 --- a/planet.rb +++ b/planet.rb @@ -1,5 +1,5 @@ +# Wave 1 class Planet - #Wave 1 def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact) @name = name @color = color diff --git a/solar_system.rb b/solar_system.rb index 33638f27..a63ac19b 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -1,5 +1,38 @@ # Wave 2 +class SolarSystem + attr_reader = :star_name, :planets + + def initialize(star_name) + @star_name = star_name + @planets = [] + end + + def add_planet(planet) + @planets.push(planet) + end + + def list_planets + planet_array = [] + star_name = "Planets orbiting #{@star_name}" + @planets.each_with_index do |planet, index| + planet_array.push("#{index + 1}. #{planet.name}") + end + return "#{star_name} \n#{planet_array.join("\n")}" + end + + # Create a method SolarSystem#find_planet_by_name, that takes + # the name of a planet as a string, and returns the corresponding + # instance of Planet. The lookup should be case-insensitive, so that Earth, + # earth and eArTh all return the same planet + def find_planet_by_name(planet_string) + @planets.each do |planet| + if planet.name.upcase == planet_string.upcase + return planet + end + end + end +end From a9ac21d68167c98c77116b92b4960bad59c139f8 Mon Sep 17 00:00:00 2001 From: Dominique Date: Tue, 20 Aug 2019 22:53:17 -0700 Subject: [PATCH 3/3] wave 3 complete main-wave3.rb --- main-wave3.rb | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ main.rb | 4 ++-- solar_system.rb | 6 +---- 3 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 main-wave3.rb diff --git a/main-wave3.rb b/main-wave3.rb new file mode 100644 index 00000000..e8067d3e --- /dev/null +++ b/main-wave3.rb @@ -0,0 +1,62 @@ +# Wave 3 +# Since wave 3 required replacing the driver code in our main method, +# I choose to create another file for Wave 3. + +require_relative "planet" +require_relative "solar_system" + +def main + # Wave 3 + solar_system = SolarSystem.new("Sun") + saturn = Planet.new("Saturn", "Blue", "13.e56", "4.98e33", "Has a ring around it") + pluto = Planet.new("Pluto", "Very Blue", "45.e87", "2.34e8", "Isn't actually a planet") + neptune = Planet.new("Neptune", "Very Very Blue", "87.e45", "3.45e3", "Really cold") + + solar_system.add_planet(saturn) + solar_system.add_planet(pluto) + solar_system.add_planet(neptune) + + def planet_details(solar_system) + puts "Which planet would you like to learn about?" + planet = gets.chomp + found_planet = solar_system.find_planet_by_name(planet) + return found_planet.summary + end + + def add_planet(solar_system) + planet_details_array = [] + # puts "What are the details of this planet? Provide the following. \nname: \ncolor: \nmass_kg: \ndistance: \nfun fact:" + puts "What is the name of this planet?" + planet_details_array.push(gets.chomp) + puts "What is the color of this planet?" + planet_details_array.push(gets.chomp) + puts "What is the mass_kg of this planet?" + planet_details_array.push(gets.chomp) + puts "What is the distance of this planet from the Sun?" + planet_details_array.push(gets.chomp) + puts "What is a fun fact about this planet?" + planet_details_array.push(gets.chomp) + planet = Planet.new(planet_details_array[0], planet_details_array[1], planet_details_array[2], planet_details_array[3], + planet_details_array[4]) + return solar_system.add_planet(planet) + end + + user_input = "A" + + while user_input == "A" || user_input == "B" || user_input == "C" + puts "What would you like to do next? \nA: List planets \nB: Planet Details \nC: Add Planet \nD: Exit Program" + user_input = gets.chomp + case user_input + when "A" + puts solar_system.list_planets + when "B" + puts planet_details(solar_system) + when "C" + add_planet(solar_system) + when "D" + user_input = "D" + end + end +end + +main \ No newline at end of file diff --git a/main.rb b/main.rb index 3fb6a57d..dede7b3b 100644 --- a/main.rb +++ b/main.rb @@ -9,8 +9,8 @@ def main venus = Planet.new("Venus", "Brown", "39.e39", "20", "2nd Hottest Planet") mars = Planet.new("Mars", "Brown-Orange", "40.e27", "30", "Super Rocky") - puts earth.summary - + puts "\n#{earth.summary}" + # Wave 2 solar_system = SolarSystem.new("Sun") solar_system.add_planet(mercury) diff --git a/solar_system.rb b/solar_system.rb index a63ac19b..43dfc725 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -15,17 +15,13 @@ def add_planet(planet) def list_planets planet_array = [] - star_name = "Planets orbiting #{@star_name}" + star_name = "\nPlanets orbiting #{@star_name}" @planets.each_with_index do |planet, index| planet_array.push("#{index + 1}. #{planet.name}") end return "#{star_name} \n#{planet_array.join("\n")}" end - # Create a method SolarSystem#find_planet_by_name, that takes - # the name of a planet as a string, and returns the corresponding - # instance of Planet. The lookup should be case-insensitive, so that Earth, - # earth and eArTh all return the same planet def find_planet_by_name(planet_string) @planets.each do |planet| if planet.name.upcase == planet_string.upcase