From 358d887468a6f120a2c38d52379a2a15ac6b18f0 Mon Sep 17 00:00:00 2001 From: ricecakemonster Date: Tue, 14 Feb 2017 23:02:00 -0800 Subject: [PATCH 1/5] Create solar_system.rb --- solar_system.rb | 133 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 solar_system.rb diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..161926af --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,133 @@ +class Planet + attr_accessor :name, :distance_from_the_sun, :radius, :mass, :moons, :density, :gravity, :rate_solar_rotation + + def initialize(planet_hash) + @name = planet_hash[:name] + @distance_from_the_sun = planet_hash[:distance_from_the_sun] + @radius = planet_hash[:radius] + @mass = planet_hash[:mass] + @moons = planet_hash[:moons] + @density = planet_hash[:density] + @gravity = planet_hash[:gravity] + @rate_solar_rotation = planet_hash[:rate_solar_rotation] + end + + def info + puts "\nPlanet #{@name}'s' radius is #{@radius} and its mass is #{@mass}. It is #{@distance_from_the_sun} miles away from the Sun and has #{@moons} moon(s)." + puts "Its density is #{@density} and its gravity is #{@gravity}. " + end + +end + + +class SolarSystem + attr_accessor :planets + + def initialize + @planets = [] + end + + def add_a_planet(planet) + + @planets.push (planet) + end + + def add_a_list(more_planets) + n = 0 + more_planets.planets.length.times do + @planets << more_planets.planets[n] + n =+ 1 + end + end + + def find_planet(planet_name) #solar_system.find_planet(whatever).distance_from_the_sun + i = 0 + @planets.length.times do + if planet_name.downcase == @planets[i].name.downcase + return @planets[i] + break + else + i = i + 1 + end + end + end + + def distance(planetA_name, planetB_name) #example: solar_system.distance("mercury", "earth") + planetA = self.find_planet(planetA_name) + planetB = self.find_planet(planetB_name) + mi_between_planets = (planetA.distance_from_the_sun.delete(',').to_i - planetB.distance_from_the_sun.delete(',').to_i ).abs + end + +end + +solar_system= SolarSystem.new + +solar_system.add_a_planet(Planet.new(name: "Jupiter", distance_from_the_sun: "483,600,000", radius: "43,441 mi", mass: "1.898 × 10^27 kg", moons: 16, density: "1.33 g/cm³", gravity: "24.79 m/s²", rate_solar_rotation: 0.416)) + +solar_system.add_a_planet(Planet.new(name: "Saturn", distance_from_the_sun: "886,700,000", radius: "36,184 mi", mass: "5.683 × 10^26 kg", moons: 53, density: "687 kg/m³",gravity: "10.44 m/s²", rate_solar_rotation: 0.437)) + +solar_system.add_a_planet(Planet.new(name: "Mercury", distance_from_the_sun: "36,000,000", radius: "1,516 mi", mass: "3.285 × 10^23 kg", moons: 0, density: "5.43 g/cm³", gravity: "3.7 m/s²", rate_solar_rotation: 58.64)) + +solar_system.add_a_planet(Planet.new(name: "Venus", distance_from_the_sun: "67,200,000", radius: "3,760 mi", mass: "4.867 × 10^24 kg", moons: 0, density: "5.24 g/cm³", gravity: "8.87 m/s²", rate_solar_rotation: 243.02)) + +solar_system.add_a_planet(Planet.new(name: "Mars", distance_from_the_sun: "141,600,000", radius: "2,106 mi", mass: "6.39 × 10^23 kg", moons: 2, density: "3.93 g/cm³", gravity: "3.711 m/s²", rate_solar_rotation: 1.02)) + +more_solar_system = SolarSystem.new + +more_solar_system.add_a_planet(Planet.new(name: "Earth", distance_from_the_sun: "92,960,000", radius: "3,959 mi", mass: "5.972 × 10^24 kg", moons: 0, density: "5.51 g/cm³", gravity: "9.807 m/s²", rate_solar_rotation: 365)) +more_solar_system.add_a_planet(Planet.new(name: "Uranus", distance_from_the_sun: "1,784,000,000", radius: "15,759 mi", mass: "8.681 × 10^25 kg", moons: 27, density: "1.27 g/cm³", gravity: "8.69 m/s²", rate_solar_rotation: 0.7)) + + +solar_system.add_a_list(more_solar_system) + + + +print "Choose the planet you want to learn about.\nChoose from Jupiter, Saturn, Mercury, Venus, Mars, Earth, Uranus (N to quit): " +entered_planet = gets.chomp.downcase +while true + if entered_planet.downcase == "n" + break + else + num = 0 + info_planet = nil + while info_planet == nil + i = 0 + solar_system.planets.length.times do + if entered_planet == solar_system.planets[i].name.downcase + info_planet = entered_planet + num = i + break + else + i += 1 + end + end + if info_planet != nil + break + else + print "Re-Enter the name of a planet you want to learn about.\nChoose from Jupiter, Saturn, Mercury, Venus, Mars, Earth, Uranus: " + entered_planet = gets.chomp.downcase + end + end + end + puts solar_system.planets[num].info + print "Choose the planet you want to learn about.\nChoose from Jupiter, Saturn, Mercury, Venus, Mars, Earth, Uranus (N to quit): " + entered_planet = gets.chomp.downcase +end + +print "Do you want to know the distance between planets? (Y to continue, N to quit)" +answer_dis = gets.chomp.downcase + +def separate_comma(number) + number.to_s.chars.to_a.reverse.each_slice(3).map(&:join).join(",").reverse +end + +if answer_dis == "n" + exit +else + print "Enter the first planet. Jupiter, Saturn, Mercury, Venus, Mars, Earth, Uranus: " + f_planet = gets.chomp + print "Enter the second planet. Jupiter, Saturn, Mercury, Venus, Mars, Earth, Uranus: " + s_planet = gets.chomp + distance = separate_comma(solar_system.distance(f_planet, s_planet)) + puts "Distance between #{f_planet.capitalize} and #{s_planet.capitalize} is #{distance} miles." +end From 5d9d828de1ffdff1f5bd4ed04cb5f7157739bbc9 Mon Sep 17 00:00:00 2001 From: ricecakemonster Date: Wed, 15 Feb 2017 09:55:08 -0800 Subject: [PATCH 2/5] Update solar_system.rb --- solar_system.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/solar_system.rb b/solar_system.rb index 161926af..b4686b41 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -33,11 +33,7 @@ def add_a_planet(planet) end def add_a_list(more_planets) - n = 0 - more_planets.planets.length.times do - @planets << more_planets.planets[n] - n =+ 1 - end + @planets += more_planets.planets end def find_planet(planet_name) #solar_system.find_planet(whatever).distance_from_the_sun From a4bc3faa61226d10f6f4eae5736bde21adc16c20 Mon Sep 17 00:00:00 2001 From: Hyunji Kim Date: Thu, 16 Feb 2017 09:37:09 -0800 Subject: [PATCH 3/5] testing out the github commands --- solar_system.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/solar_system.rb b/solar_system.rb index b4686b41..ac97f52d 100644 --- a/solar_system.rb +++ b/solar_system.rb @@ -1,3 +1,4 @@ +#testing out the github commands class Planet attr_accessor :name, :distance_from_the_sun, :radius, :mass, :moons, :density, :gravity, :rate_solar_rotation From ab4ba046290a55aa251e58993a63be319c4bacdd Mon Sep 17 00:00:00 2001 From: Hyunji Kim Date: Thu, 16 Feb 2017 09:50:45 -0800 Subject: [PATCH 4/5] just a test --- test.rb | 1 + 1 file changed, 1 insertion(+) create mode 100644 test.rb diff --git a/test.rb b/test.rb new file mode 100644 index 00000000..e263d9a0 --- /dev/null +++ b/test.rb @@ -0,0 +1 @@ +puts "test this git" From f341372f308795a67a5afcb72ea752d82e003cfd Mon Sep 17 00:00:00 2001 From: Hyunji Kim Date: Thu, 16 Feb 2017 09:52:22 -0800 Subject: [PATCH 5/5] deleted a file --- test.rb | 1 - 1 file changed, 1 deletion(-) delete mode 100644 test.rb diff --git a/test.rb b/test.rb deleted file mode 100644 index e263d9a0..00000000 --- a/test.rb +++ /dev/null @@ -1 +0,0 @@ -puts "test this git"