From 072c9b4f74bb28179e096954da2e8a7a5a0a87bf Mon Sep 17 00:00:00 2001 From: CheerOnMars <36147056+CheerOnMars@users.noreply.github.com> Date: Mon, 12 Feb 2018 08:41:11 -0800 Subject: [PATCH 1/6] Create solar_system_wave1.rb --- solar_system_wave1.rb | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 solar_system_wave1.rb diff --git a/solar_system_wave1.rb b/solar_system_wave1.rb new file mode 100644 index 00000000..7ea45f5e --- /dev/null +++ b/solar_system_wave1.rb @@ -0,0 +1,51 @@ +# Create a SolarSystem class with an @planets instance variable. +# Create an initialize method which should take a collection of planet names and store them in an @planets instance variable. +# Create a method that adds a planet to the list (not using user input). +# Create a method which will return, not print, a list of the planets as a String. +# Write code to test your SolarSystem +# Modify SolarSystem's initialize method to take a list of hashes where each planet is sent as a hash with at least 5 attributes. + +# Define the class +class SolarSystem + +# reader for planet + def planets + return @planets + end + +# writer for planet + def planets=(new_planet) + @planets = new_planet + end + + attr_accessor :order + +# initialize method + def initialize(planets) + @planets = planets + end + + def self.planets + return @planets + end + + @planets = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"] + +end + +# code to test +SolarSystem.planets.each_with_index do |planet, i| + puts "#{i+1}. #{planet}" +end + + + +mercury = { planets: "MercuryA", radius: 1516, moons: 0, rotation_period: 58.646, orbit_period: 0.2408467, rings: "No" } +venus = { planets: "VenusA", radius: 3760, moons: 0, rotation_period: -243.018, orbit_period: 0.61519726, rings: "No"} +earth = { planets: "EarthA", radius: 6371, moons: 1, rotation_period: 0.99726968, orbit_period: 1.0000174, rings: "No" } +mars = { planets: "MarsA", radius: 3389, moons: 2, rotation_period: 1.026, orbit_period: 1.8808476, rings: "No" } +jupiter = { planets: "JupiterA", radius: 69911 , moons: 69, rotation_period: 0.41354, orbit_period: 11.862615, rings: "Yes" } +saturn = { planets: "SaturnA", radius: 58232, moons: 62, rotation_period: 0.444, orbit_period: 29.447498, rings: "Yes" } +uranus = { planets: "UranusA", radius: 25362 , moons: 27, rotation_period: -0.718, orbit_period: 84.016846, rings: "Yes" } +neptune = { planets: "NeptuneA", radius: 24622 , moons: 14, rotation_period: 0.671, orbit_period: 164.79132, rings: "Yes" } + From 77bbb5dd95544ca6a0319552d6ac2860908230f3 Mon Sep 17 00:00:00 2001 From: CheerOnMars <36147056+CheerOnMars@users.noreply.github.com> Date: Mon, 12 Feb 2018 08:41:50 -0800 Subject: [PATCH 2/6] Create solar_system_wave2.rb --- solar_system_wave2.rb | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 solar_system_wave2.rb diff --git a/solar_system_wave2.rb b/solar_system_wave2.rb new file mode 100644 index 00000000..d8d4ad74 --- /dev/null +++ b/solar_system_wave2.rb @@ -0,0 +1,74 @@ +# Create a SolarSystem class with an @planets instance variable. +# Create an initialize method which should take a collection of planet names and store them in an @planets instance variable. +# Create a method that adds a planet to the list (not using user input). +# Create a method which will return, not print, a list of the planets as a String. +# Write code to test your SolarSystem +# Modify SolarSystem's initialize method to take a list of hashes where each planet is sent as a hash with at least 5 attributes. + +# Define the class +class SolarSystem + + def initialize(planets) + @planets = planets + end + + attr_reader :planets + + def puts_self + puts self + end + + def self.planets + return @planets + end + + arr_planets = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"] + + @planets = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"] + +end + +class Planet + + attr_reader :name + attr_reader :order + attr_reader :radius + attr_reader :moons + + def initialize(name, order, radius, moons) + @name = name + @order = order + @radius = radius + @moons = moons + end + + def puts_self + puts self + end + + def self.name + return @name + end + + # instance method + def summary + return " #{order}. #{name} - Radius: #{radius}km. Number of Moons: #{moons}." + end + + def self.summary + return @summary + end + + + mercury = Planet.new("Mercury", 1, 2440 , 0) + venus = Planet.new("Venus", 2, 6052 , 0) + earth = Planet.new("Earth", 3, 6371 ,1) + + puts + puts mercury.summary + puts venus.summary + puts earth.summary + puts + +end + From e5a49760929ca72c1fbd57ecb535b58b57a111eb Mon Sep 17 00:00:00 2001 From: CheerOnMars <36147056+CheerOnMars@users.noreply.github.com> Date: Mon, 12 Feb 2018 10:28:24 -0800 Subject: [PATCH 3/6] Update solar_system_wave2.rb --- solar_system_wave2.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/solar_system_wave2.rb b/solar_system_wave2.rb index d8d4ad74..c7331991 100644 --- a/solar_system_wave2.rb +++ b/solar_system_wave2.rb @@ -30,10 +30,10 @@ def self.planets class Planet - attr_reader :name - attr_reader :order - attr_reader :radius - attr_reader :moons + attr_accessor :name + attr_accessor :order + attr_accessor :radius + attr_accessor :moons def initialize(name, order, radius, moons) @name = name From ff31605b33f787aa2e8fdaa80de67706a8b437d2 Mon Sep 17 00:00:00 2001 From: CheerOnMars <36147056+CheerOnMars@users.noreply.github.com> Date: Mon, 12 Feb 2018 12:26:39 -0800 Subject: [PATCH 4/6] Create solar_system_wave1b.rb --- solar_system_wave1b.rb | 134 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 solar_system_wave1b.rb diff --git a/solar_system_wave1b.rb b/solar_system_wave1b.rb new file mode 100644 index 00000000..0f6331e5 --- /dev/null +++ b/solar_system_wave1b.rb @@ -0,0 +1,134 @@ +# Create a SolarSystem class with an @planets instance variable. +# Create an initialize method which should take a collection of planet names and store them in an @planets instance variable. +# Create a method that adds a planet to the list (not using user input). +# Create a method which will return, not print, a list of the planets as a String. +# Write code to test your SolarSystem +# Modify SolarSystem's initialize method to take a list of hashes where each planet is sent as a hash with at least 5 attributes. + +# Define the class +class SolarSystem + +# reader for planet + def planets + return @planets + end + +# writer for planet + def planets=(new_planet) + @planets = new_planet + end + + #attr_accessor :order, + attr_accessor :radius + attr_accessor :moons + attr_accessor :rotation_period + attr_accessor :orbit_period + attr_accessor :rings + + +# initialize method + def initialize(planets_hash) + @planets = planets_hash[:planets] + @radius = planets_hash[:radius] + @moons = planets_hash[:moons] + @rotation_period = planets_hash[:rotation_period] + @orbit_period = planets_hash[:orbit_period] + @rings = planets_hash[:rings] + end + + def self.planets + return @planets + end + + #@planets = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"] + +end + +puts +mercury = SolarSystem.new ({ + planets: "MercuryA", + radius: 1516, + moons: 0, + rotation_period: 58.646, + orbit_period: 0.2408467, + rings: "No" +}) + + +venus = SolarSystem.new ({ + planets: "VenusA", + radius: 3760, + moons: 0, + rotation_period: -243.018, + orbit_period: 0.61519726, + rings: "No" +}) + + +earth = SolarSystem.new ({ + planets: "EarthA", + radius: 6371, + moons: 1, + rotation_period: 0.99726968, + orbit_period: 1.0000174, + rings: "No" +}) + +mars = SolarSystem.new ({ + planets: "MarsA", + radius: 3389, + moons: 2, + rotation_period: 1.026, + orbit_period: 1.8808476, + rings: "No" +}) + +jupiter = SolarSystem.new ({ + planets: "JupiterA", + radius: 69911 , + moons: 69, + rotation_period: 0.41354, + orbit_period: 11.862615, + rings: "Yes" +}) + +saturn = SolarSystem.new ({ + planets: "SaturnA", + radius: 58232, + moons: 62, + rotation_period: 0.444, + orbit_period: 29.447498, + rings: "Yes" +}) +uranus = SolarSystem.new ({ + planets: "UranusA", + radius: 25362 , + moons: 27, + rotation_period: -0.718, + orbit_period: 84.016846, + rings: "Yes" +}) +neptune = SolarSystem.new ({ + planets: "NeptuneA", + radius: 24622 , + moons: 14, + rotation_period: 0.671, + orbit_period: 164.79132, + rings: "Yes" }) + +puts mercury.planets +puts +puts venus.planets +puts +puts earth.planets +puts +puts mars.planets +puts +puts jupiter.planets +puts +puts saturn.planets +puts +puts uranus.planets +puts +puts neptune.planets +puts From dcb9fedcf5d86bdf8085b6966fa11388ede1b2e6 Mon Sep 17 00:00:00 2001 From: CheerOnMars <36147056+CheerOnMars@users.noreply.github.com> Date: Mon, 12 Feb 2018 12:28:33 -0800 Subject: [PATCH 5/6] Update solar_system_wave2.rb --- solar_system_wave2.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/solar_system_wave2.rb b/solar_system_wave2.rb index c7331991..dcb754f2 100644 --- a/solar_system_wave2.rb +++ b/solar_system_wave2.rb @@ -22,6 +22,9 @@ def self.planets return @planets end + def planet + puts + end arr_planets = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"] @planets = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"] @@ -59,16 +62,15 @@ def self.summary return @summary end +end - mercury = Planet.new("Mercury", 1, 2440 , 0) - venus = Planet.new("Venus", 2, 6052 , 0) - earth = Planet.new("Earth", 3, 6371 ,1) - - puts - puts mercury.summary - puts venus.summary - puts earth.summary - puts + planet_arr = [ + Planet.new("Mercury", 1, 2440 , 0), + Planet.new("Venus", 2, 6052 , 0), + Planet.new("Earth", 3, 6371 ,1) + ] +puts +planet_arr.each do |i| + puts i.summary end - From a5dbe7ca15a825b05fbdf5969ea14ffedcb3da30 Mon Sep 17 00:00:00 2001 From: CheerOnMars <36147056+CheerOnMars@users.noreply.github.com> Date: Mon, 12 Feb 2018 20:23:41 -0800 Subject: [PATCH 6/6] Create solar_system_wave3.rb --- solar_system_wave3.rb | 109 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 solar_system_wave3.rb diff --git a/solar_system_wave3.rb b/solar_system_wave3.rb new file mode 100644 index 00000000..5a17db55 --- /dev/null +++ b/solar_system_wave3.rb @@ -0,0 +1,109 @@ +class SolarSystem + + def initialize(planets) + @planets = planets + end + + attr_reader :planets + + def puts_self + puts self + end + + def self.planets + return @planets + end +end + +class Planet + + attr_accessor :name, :order, :radius, :moons + + def initialize(name, order, radius, moons) + @name = name + @order = order + @radius = radius + @moons = moons + end + + def puts_self + puts self + end + + def self.name + return @name + end + + # instance method + def contents + return " #{order}. #{name}" + end + + def self.contents + return @contents + end + + def summary + return " #{name} - Radius: #{radius}km. Number of Moons: #{moons}." + end + + def self.summary + return @summary + end + +end + +# input planets + planet_arr = [ + Planet.new("Mercury", 1, 2440, 0), + Planet.new("Venus", 2, 6052, 0), + Planet.new("Earth", 3, 6371, 1), + Planet.new("Mars", 4, 3390, 2), + Planet.new("Jupiter", 5, 69911, 2), + Planet.new("Saturn", 6, 58232, 2), + Planet.new("Uranus", 7, 25362, 2), + Planet.new("Neptune", 8, 24622, 2), + ] + +#outputs planets +puts +print "Welcome to this Solar System directory! Here is a list of planets: " +puts +planet_arr.each_with_index do |planet, i| + puts "#{i+1}. #{planet.name}" +end + +puts +print "Type LEARN to learn about a planet. Type NEW to add a new planet: " +selection = gets.chomp.upcase! +if selection == "LEARN" + print "Please type the number of the planet you'd like to learn about: " + learn_option = gets.chomp.to_i + counter = 0 + until learn_option >= 0 && learn_option <= planet_arr.length + counter += 1 + if counter == 3 + puts "Too many incorrect attempts. Goodbye" + exit + else + print "You did not type a valid number. Please try again: " + learn_option = gets.chomp.to_i + end + end + puts planet_arr[learn_option-1].summary +elsif selection == "NEW" + print "What's the planet name? " + input_name = gets.chomp.upcase! + print "What's the radius of #{input_name} in kilometers? " + input_radius = gets.chomp.to_i + print "How many moons does #{input_name} have? " + input_moons = gets.chomp.to_i + planet_arr << Planet.new(input_name, 0, input_radius, input_moons) + puts "Here's an updated list of planets: " + planet_arr.each_with_index do |planet, i| + puts "#{i+1}. #{planet.summary} " +else + puts "You did not enter a valid option. Goodbye" +end + +end