From 9518f63d1a8c3d20fa6f7fc3c30adf29ed40cecd Mon Sep 17 00:00:00 2001 From: Shamira Date: Tue, 26 Feb 2019 18:06:01 -0800 Subject: [PATCH 1/4] solar system project finished --- main.rb | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ planet.rb | 19 ++++++++++++++ planet_spec.rb | 14 ++++++++++ solar_system.rb | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 main.rb create mode 100644 planet.rb create mode 100644 planet_spec.rb create mode 100644 solar_system.rb diff --git a/main.rb b/main.rb new file mode 100644 index 00000000..c5c9c604 --- /dev/null +++ b/main.rb @@ -0,0 +1,70 @@ +require_relative "solar_system" +require_relative "planet" + +def main + sol_system = SolarSystem.new("Sol") + mercury = Planet.new("Mercury", "red", 78939, 2000, "") + sol_system.add_planet(mercury) + + venus = Planet.new("Venus", "red", 78939, 2000, "") + sol_system.add_planet(venus) + + earth = Planet.new("Earth", "green", 100.25, 5000, "I live here!") + sol_system.add_planet(earth) + + mars = Planet.new("Mars", "red", 78939, 2000, "John Jones is from there") + sol_system.add_planet(mars) + + jupiter = Planet.new("Jupiter", "red", 78939, 2000, "") + sol_system.add_planet(jupiter) + + saturn = Planet.new("Saturn", "purple", 78939, 2000, "") + sol_system.add_planet(saturn) + + uranus = Planet.new("Uranus", "red", 78939, 2000, "") + sol_system.add_planet(uranus) + + neptune = Planet.new("Neptune", "red", 78939, 2000, "") + sol_system.add_planet(neptune) + + list = sol_system.list_planets + + puts "one" + puts sol_system.list_planets_one + #will return a summary of the planet you put in the argument + sol_system.find_planet_by_name_two("maRs").summary + + puts "Would you like a list of planets, planet details, or to exit?" + puts "Enter List to continue or exit to end the program" + + # gets user input + + loop do + list = sol_system.list_planets + input = gets.chomp.downcase + break if input == "exit" + + case input + when "list" + puts list + when "details" + puts "What planet do you want details for?" + details = gets.chomp.downcase + puts sol_system.find_planet_by_name_two(details).summary + when "add" + sol_system.new_planet + puts sol_system.list_planets + end + break + end + + puts "Goodbye!" + + # def planet_details(details) + # planet_summary = @planets.each do |planet| + # planet + # end + # end +end + +main diff --git a/planet.rb b/planet.rb new file mode 100644 index 00000000..562bb2e1 --- /dev/null +++ b/planet.rb @@ -0,0 +1,19 @@ +require_relative "solar_system" + +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}: is the color #{color}, weighs #{mass_kg}kg, and is #{distance_from_sun_km}km from the sun. Fun fact: #{fun_fact} " + end +end + +earth = Planet.new("Earth", "green", 100.25, 5000, "I live here!") diff --git a/planet_spec.rb b/planet_spec.rb new file mode 100644 index 00000000..a43310d9 --- /dev/null +++ b/planet_spec.rb @@ -0,0 +1,14 @@ +require "minitest/autorun" +require "minitest/reporters" +require_relative "planet" + +Minitest::Reporters.use! + +describe "planet" do + it "will return a string" do + home_planet = earth.summary + earth = Planet.new("Earth", "green", 100.25, 5000, "I live here!") + + expect(home_planet).must_be_instance_of String + end +end diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..39d6f8ea --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,68 @@ + + +class SolarSystem + attr_reader :star_name, :planets + + def initialize(star_name) + @star_name = star_name + @planets = [] + end + + # Create a method add_planet, + #which will take an instance of Planet as a parameter and add it to the list of planets. + def add_planet(planet) #Planet.name + #iterate through each Planet.name and put it in the @planets array. + @planets << planet + end + + def list_planets + result = "Planets orbitting:\n" + planet_names = @planets.map do |planet| + planet.name + end + planet_names.each_with_index do |name, index| + result += "#{index + 1}. #{name}\n" + end + return result + # @planets.name specify that you're searching the name + end + + def list_planets_one + result = "Planets orbitting:\n" + @planets.each_with_index do |planet, index| + result += "#{index + 1}. #{planet.name}\n" + end + return result + end + + def find_planet_by_name(name) + lowercase_name_to_planet_hash = {} + @planets.each do |planet| + lowercase_name_to_planet_hash[planet.name.downcase] = planet + end + return lowercase_name_to_planet_hash[name.downcase] + end + + def find_planet_by_name_two(name) + return @planets.find do |planet| + planet.name.downcase == name.downcase + end + end + + def new_planet + puts "Add planet name:" + name = gets.chomp.downcase + puts "Add color:" + color = gets.chomp + puts "Add mass in kg:" + mass_kg = gets.chomp.to_i + puts "Distance from the sun?" + distance_from_sun_km = gets.chomp.to_i + puts "What is a fun fact about your planet?" + fun_fact = gets.chomp + user_input_planet = (Planet.new(name, color, mass_kg, distance_from_sun_km, fun_fact)) + # planet(user_input_planet) + # puts sol_system.new_planet.summary + add_planet(user_input_planet) + end +end From 622a837bee824026b7bf08afe0ef352e06a8971b Mon Sep 17 00:00:00 2001 From: Shamira Date: Wed, 27 Feb 2019 08:26:18 -0800 Subject: [PATCH 2/4] edits to main.rb and planet.rb --- main.rb | 2 +- planet.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main.rb b/main.rb index c5c9c604..bde24e26 100644 --- a/main.rb +++ b/main.rb @@ -34,7 +34,7 @@ def main #will return a summary of the planet you put in the argument sol_system.find_planet_by_name_two("maRs").summary - puts "Would you like a list of planets, planet details, or to exit?" + puts "Would you like a list of planets, planet details, to add a planet, or to exit?" puts "Enter List to continue or exit to end the program" # gets user input diff --git a/planet.rb b/planet.rb index 562bb2e1..a22634d0 100644 --- a/planet.rb +++ b/planet.rb @@ -1,4 +1,4 @@ -require_relative "solar_system" + class Planet attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact From ded4e6c13a0e40aab247f82f05b4c6b7148b0e55 Mon Sep 17 00:00:00 2001 From: Shamira Date: Wed, 27 Feb 2019 08:38:07 -0800 Subject: [PATCH 3/4] organization clean up --- main.rb | 16 ++++++++-------- planet.rb | 2 -- solar_system.rb | 14 +++++++------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/main.rb b/main.rb index bde24e26..ceb8daad 100644 --- a/main.rb +++ b/main.rb @@ -3,28 +3,28 @@ def main sol_system = SolarSystem.new("Sol") - mercury = Planet.new("Mercury", "red", 78939, 2000, "") - sol_system.add_planet(mercury) + gem_homeland = Planet.new("Gem Homeland", "crystal", 78939, 287200, "Home of the Crystal Gems.") + sol_system.add_planet(gem_homeland) - venus = Planet.new("Venus", "red", 78939, 2000, "") + venus = Planet.new("Venus", "purple", 78939, 2000, "The brightest object in our solar system after the sun and the moon. ") sol_system.add_planet(venus) - earth = Planet.new("Earth", "green", 100.25, 5000, "I live here!") + earth = Planet.new("Earth", "blue", 100.25, 5000, "I live here!") sol_system.add_planet(earth) mars = Planet.new("Mars", "red", 78939, 2000, "John Jones is from there") sol_system.add_planet(mars) - jupiter = Planet.new("Jupiter", "red", 78939, 2000, "") + jupiter = Planet.new("Jupiter", "yellow", 78939, 2000, "The fastest rotating planet in the solar system.") sol_system.add_planet(jupiter) - saturn = Planet.new("Saturn", "purple", 78939, 2000, "") + saturn = Planet.new("Saturn", "purple with rings", 78939, 2000, "My fav planet!") sol_system.add_planet(saturn) - uranus = Planet.new("Uranus", "red", 78939, 2000, "") + uranus = Planet.new("Uranus", "orange", 78939, 2000, "lol") sol_system.add_planet(uranus) - neptune = Planet.new("Neptune", "red", 78939, 2000, "") + neptune = Planet.new("Neptune", "green", 78939, 2000, "Not to be confused with the King of Bikini Bottom.") sol_system.add_planet(neptune) list = sol_system.list_planets diff --git a/planet.rb b/planet.rb index a22634d0..dfb91442 100644 --- a/planet.rb +++ b/planet.rb @@ -1,5 +1,3 @@ - - class Planet attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact diff --git a/solar_system.rb b/solar_system.rb index 39d6f8ea..4afdc13c 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -35,13 +35,13 @@ def list_planets_one return result end - def find_planet_by_name(name) - lowercase_name_to_planet_hash = {} - @planets.each do |planet| - lowercase_name_to_planet_hash[planet.name.downcase] = planet - end - return lowercase_name_to_planet_hash[name.downcase] - end + # def find_planet_by_name(name) + # lowercase_name_to_planet_hash = {} + # @planets.each do |planet| + # lowercase_name_to_planet_hash[planet.name.downcase] = planet + # end + # return lowercase_name_to_planet_hash[name.downcase] + # end def find_planet_by_name_two(name) return @planets.find do |planet| From 09a7fd4b04b79df924f4b71518fc4ba0a92f7243 Mon Sep 17 00:00:00 2001 From: Shamira Date: Wed, 27 Feb 2019 10:20:23 -0800 Subject: [PATCH 4/4] edits --- main.rb | 10 ++-------- solar_system.rb | 10 ---------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/main.rb b/main.rb index ceb8daad..42ed507a 100644 --- a/main.rb +++ b/main.rb @@ -29,12 +29,12 @@ def main list = sol_system.list_planets - puts "one" puts sol_system.list_planets_one #will return a summary of the planet you put in the argument - sol_system.find_planet_by_name_two("maRs").summary + # sol_system.find_planet_by_name_two("maRs").summary puts "Would you like a list of planets, planet details, to add a planet, or to exit?" + puts "Enter (list), (details), (add), or (exit)." puts "Enter List to continue or exit to end the program" # gets user input @@ -59,12 +59,6 @@ def main end puts "Goodbye!" - - # def planet_details(details) - # planet_summary = @planets.each do |planet| - # planet - # end - # end end main diff --git a/solar_system.rb b/solar_system.rb index 4afdc13c..3f2df2df 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -1,5 +1,3 @@ - - class SolarSystem attr_reader :star_name, :planets @@ -35,14 +33,6 @@ def list_planets_one return result end - # def find_planet_by_name(name) - # lowercase_name_to_planet_hash = {} - # @planets.each do |planet| - # lowercase_name_to_planet_hash[planet.name.downcase] = planet - # end - # return lowercase_name_to_planet_hash[name.downcase] - # end - def find_planet_by_name_two(name) return @planets.find do |planet| planet.name.downcase == name.downcase