From 9aa1ded19a6dad156fc6c67ff166651c6c1c0b36 Mon Sep 17 00:00:00 2001 From: Chantal Demissie <42252976+ChantalDemissie@users.noreply.github.com> Date: Wed, 27 Feb 2019 11:18:49 -0800 Subject: [PATCH 1/4] Add files via upload still working on wave 3 --- main.rb | 22 ++++++++++++++++++ planet.rb | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ solar_system.rb | 35 +++++++++++++++++++++++++++++ 3 files changed, 116 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..1c1feade --- /dev/null +++ b/main.rb @@ -0,0 +1,22 @@ +require_relative "Planet" +require_relative "Solar_System" + +def main + mars = Planet.new("Mars", "red", 6.3E23, 227.9E9, "greek god of war Aries planet") + venus = Planet.new("Venus", "pink", 4.86E24, 108E9, "greek goddess of love Aphrodites planet") + puts "the distance from the sun to #{mars.name} is #{mars.distance_from_sun_km} kilometers" + puts "the mass of #{venus.name} is #{venus.mass_kg} kilograms" + puts venus.summary #notreturn + + solar_system = SolarSystem.new("Solus") + neptune = Planet.new("Neptune", "blue", 1.02E26, 4.495E9, "greek god of the sea Poseidons planet") + mars = Planet.new("Mars", "red", 6.3E23, 227.9E9, "greek god of war Aries planet") + venus = Planet.new("Venus", "pink", 4.86E24, 108E9, "greek goddess of love Aphrodites planet") + solar_system.add_planet(neptune) + solar_system.add_planet(mars) + solar_system.add_planet(venus) + list = solar_system.list_planets + puts list +end + +main diff --git a/planet.rb b/planet.rb new file mode 100644 index 00000000..2400243b --- /dev/null +++ b/planet.rb @@ -0,0 +1,59 @@ +class Planet + 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 name + return @name + end + + def name=(name) + @name = name + end + + def color + return @color + end + + def color=(color) + @color = color + end + + def mass_kg + return @mass_kg + end + + def mass_kg=(mass_kg) + @mass_kg = mass_kg + end + + def distance_from_sun_km + return @distance_from_sun_km + end + + def distance_from_sun_km=(distance_from_sun_km) + @distance_from_sun_km = distance_from_sun_km + end + + def fun_fact + return @fun_fact + end + + def fun_fact=(fun_fact) + @fun_fact = fun_fact + end + + def summary + return "The planet #{@name} is the color #{@color}. A neat fact about the planet: #{@fun_fact}." + end +end + +# Load Planet into pry: +# $ pry -r ./planet.rb +mars = Planet.new("Mars", "red", 6.3E23, 227.9E9, "greek god of war Aries planet") +venus = Planet.new("Venus", "pink", 4.86E24, 108E9, "greek goddess of love Aphrodites planet") +jupiter = Planet.new("Neptune", "blue", 1.02E26, 4.495E9, "greek god of the sea Poseidons planet") diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..45a34d30 --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,35 @@ +class SolarSystem + def initialize(star_name) + @star_name = star_name + @planets = [] + end + + def star_name + return @star_name + end + + def planets + return @planets + end + + def add_planet(planet) + @planets.push(planet) + end + + def list_planets + str = "Planets orbiting #{@star_name}\n" + @planets.each_with_index do |planet, index| + str += "#{index + 1}. #{planet.name}\n" + end + return str + end + + def find_planet_by_name(planet_name) + @planets.each do |planet| + if planet_name.upcase == planet.name.upcase + return planet + end + end + return nil + end +end From 16951f07606701c2f25ce055dcda2f8d2af92a6e Mon Sep 17 00:00:00 2001 From: Chantal Demissie <42252976+ChantalDemissie@users.noreply.github.com> Date: Fri, 1 Mar 2019 15:28:36 -0800 Subject: [PATCH 2/4] Update main.rb wave 3 list planets, planet details working. --- main.rb | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/main.rb b/main.rb index 1c1feade..1ad013bb 100644 --- a/main.rb +++ b/main.rb @@ -2,12 +2,6 @@ require_relative "Solar_System" def main - mars = Planet.new("Mars", "red", 6.3E23, 227.9E9, "greek god of war Aries planet") - venus = Planet.new("Venus", "pink", 4.86E24, 108E9, "greek goddess of love Aphrodites planet") - puts "the distance from the sun to #{mars.name} is #{mars.distance_from_sun_km} kilometers" - puts "the mass of #{venus.name} is #{venus.mass_kg} kilograms" - puts venus.summary #notreturn - solar_system = SolarSystem.new("Solus") neptune = Planet.new("Neptune", "blue", 1.02E26, 4.495E9, "greek god of the sea Poseidons planet") mars = Planet.new("Mars", "red", 6.3E23, 227.9E9, "greek god of war Aries planet") @@ -16,7 +10,43 @@ def main solar_system.add_planet(mars) solar_system.add_planet(venus) list = solar_system.list_planets - puts list + + found_planet = solar_system.find_planet_by_name("Venus") + + input = "" + + until input == "exit" + puts "what would you like to do? list planets, planet details, create planet, exit" + input = gets.chomp + if input == "list planets" + list = solar_system.list_planets + puts list + elsif input == "planet details" + puts "what planet do you want to learn about?" + user_add_planet = gets.chomp + chosen_planet = solar_system.find_planet_by_name(user_add_planet) + puts chosen_planet.summary + elsif input == "create planet" + planet.new = add_user_planet + solar_system.add_planet(add_user_planet) + else + puts "toodles!" + end + end +end + +def add_new_planet + puts "What is the name of the planet?" + name = gets.chomp.capitalize + puts "What color is the planet?" + color = gets.chomp.downcase + puts "What is the planet's mass in kilograms?" + mass_kg = gets.chomp.to_f + puts "What is the planet's distance from A Wrinkle in Time?" + distance_from_sun_km = gets.chomp.to_i + puts "What is a fun fact about the planet?" + fun_fact = gets.chomp + new_planet = Planet.new(name, color, mass_kg, distance_from_sun_km, fun_fact) end main From 965b64d4ab4ede9a7f61e7ca84dbec8ac3ea7c64 Mon Sep 17 00:00:00 2001 From: Chantal Demissie <42252976+ChantalDemissie@users.noreply.github.com> Date: Fri, 1 Mar 2019 15:44:32 -0800 Subject: [PATCH 3/4] Delete main.rb --- main.rb | 52 ---------------------------------------------------- 1 file changed, 52 deletions(-) delete mode 100644 main.rb diff --git a/main.rb b/main.rb deleted file mode 100644 index 1ad013bb..00000000 --- a/main.rb +++ /dev/null @@ -1,52 +0,0 @@ -require_relative "Planet" -require_relative "Solar_System" - -def main - solar_system = SolarSystem.new("Solus") - neptune = Planet.new("Neptune", "blue", 1.02E26, 4.495E9, "greek god of the sea Poseidons planet") - mars = Planet.new("Mars", "red", 6.3E23, 227.9E9, "greek god of war Aries planet") - venus = Planet.new("Venus", "pink", 4.86E24, 108E9, "greek goddess of love Aphrodites planet") - solar_system.add_planet(neptune) - solar_system.add_planet(mars) - solar_system.add_planet(venus) - list = solar_system.list_planets - - found_planet = solar_system.find_planet_by_name("Venus") - - input = "" - - until input == "exit" - puts "what would you like to do? list planets, planet details, create planet, exit" - input = gets.chomp - if input == "list planets" - list = solar_system.list_planets - puts list - elsif input == "planet details" - puts "what planet do you want to learn about?" - user_add_planet = gets.chomp - chosen_planet = solar_system.find_planet_by_name(user_add_planet) - puts chosen_planet.summary - elsif input == "create planet" - planet.new = add_user_planet - solar_system.add_planet(add_user_planet) - else - puts "toodles!" - end - end -end - -def add_new_planet - puts "What is the name of the planet?" - name = gets.chomp.capitalize - puts "What color is the planet?" - color = gets.chomp.downcase - puts "What is the planet's mass in kilograms?" - mass_kg = gets.chomp.to_f - puts "What is the planet's distance from A Wrinkle in Time?" - distance_from_sun_km = gets.chomp.to_i - puts "What is a fun fact about the planet?" - fun_fact = gets.chomp - new_planet = Planet.new(name, color, mass_kg, distance_from_sun_km, fun_fact) -end - -main From 6c96b958424e38e168b5f619ba3b06ca2f439284 Mon Sep 17 00:00:00 2001 From: Chantal Demissie <42252976+ChantalDemissie@users.noreply.github.com> Date: Fri, 1 Mar 2019 16:49:29 -0800 Subject: [PATCH 4/4] Create main.rb wave 3 --- main.rb | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 main.rb diff --git a/main.rb b/main.rb new file mode 100644 index 00000000..8ba8a3c9 --- /dev/null +++ b/main.rb @@ -0,0 +1,52 @@ +require_relative "Planet" +require_relative "Solar_System" + +def main + solar_system = SolarSystem.new("Solus") + neptune = Planet.new("Neptune", "blue", 1.02E26, 4.495E9, "greek god of the sea Poseidons planet") + mars = Planet.new("Mars", "red", 6.3E23, 227.9E9, "greek god of war Aries planet") + venus = Planet.new("Venus", "pink", 4.86E24, 108E9, "greek goddess of love Aphrodites planet") + solar_system.add_planet(neptune) + solar_system.add_planet(mars) + solar_system.add_planet(venus) + list = solar_system.list_planets + + found_planet = solar_system.find_planet_by_name("Venus") + + input = "" + + until input == "exit" + puts "what would you like to do? list planets, planet details, add planet, exit" + input = gets.chomp + if input == "list planets" + list = solar_system.list_planets + puts list + elsif input == "planet details" + puts "what planet do you want to learn about?" + user_add_planet = gets.chomp + chosen_planet = solar_system.find_planet_by_name(user_add_planet) + puts chosen_planet.summary + elsif input == "add planet" + planet_new = add_new_planet + solar_system.add_planet(add_new_planet) + else + puts "toodles!" + end + end +end + +def add_new_planet + puts "What is the name of the planet?" + name = gets.chomp.capitalize + puts "What color is the planet?" + color = gets.chomp.downcase + puts "What is the planet's mass in kilograms?" + mass_kg = gets.chomp.to_f + puts "What is the planet's distance from the sun" + distance_from_sun_km = gets.chomp.to_i + puts "What is a fun fact about the planet?" + fun_fact = gets.chomp + new_planet = Planet.new(name, color, mass_kg, distance_from_sun_km, fun_fact) +end + +main