forked from Ada-C7/Solar-System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolar_system.rb
More file actions
61 lines (48 loc) · 1.71 KB
/
solar_system.rb
File metadata and controls
61 lines (48 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'colorize'
class Planet
attr_accessor :name, :diameter, :mass, :moons, :rings, :rotation, :distance_from_the_sun
def initialize (name,diameter,mass,moons,rings,rotation,distance_from_the_sun)
@name = name
@diameter = diameter
@mass = mass
@moons = moons
@rings = rings
@rotation = rotation
@distance_from_the_sun = distance_from_the_sun
end
def print_name
puts "I'm a Planet whose name is #{ @name } that has a diameter of #{ @diameter }, a mass of #{ @mass },
#{ @moons } moons, #{ @rings } rings, and has a rate of solar rotation of #{ @rotation }.
My distance from the sun is #{ @distance_from_the_sun }."
end
end
earth = Planet.new("Earth","7917 mi","5.972 × 10^24 kg","1","0","24 days","i")
jupiter = Planet.new("Jupiter","86,881.4 mi","1.898 × 10^27 kg","67","4","9 hours","i")
venus = Planet.new("Venus","7520 mi","4.867 × 10^24 kg","0","0","i","i")
planets = [earth, jupiter, venus]
planets.each do |planet|
print planet.name + " : "
planet.print_name
end
class SolarSystem
attr_reader :galaxy_name, :planets, :formation_year
def initialize (galaxy_name,formation_year)
@galaxy_name = galaxy_name
@planets = []
@formation_year = formation_year
end
def add_planets(planet_name)
@planets << planet_name
end
# def print_system
# puts "This system is the #{ @galaxy_name }, it has a formation
# year of # { @formation_year } ago."
end
milky_way = SolarSystem.new("Milky Way","13.6 billion years")
puts "This system is the #{ milky_way.galaxy_name }, it has a formation
year of #{ milky_way.formation_year } ago.".colorize(:blue)
planets.each do |planet|
milky_way.add_planets(planet)
# planets.print_system
end
milky_way.planets