forked from Ada-C6/CSV-Sample-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SolarSystem.rb
36 lines (33 loc) · 766 Bytes
/
SolarSystem.rb
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
# SolarSystem.rb
class Planet
attr_accessor :name, :distance, :mass, :moons, :diameter
def initialize(name, distance, mass, moons, diameter)
@name = name
@distance = distance
@mass = mass
@moons = moons
@diameter = diameter
end
def to_s()
return "Planet #{@name} has a mass of #{@mass}, #{@moons} moons, a diameter of #{@diameter} and is at a distance of #{@distance} from the sun."
end
end
class SolarSystem
def initialize(planets)
@planets = planets
end
def add_Planet(planet)
@planets << planets
end
def add_planets(planets)
planets.each do |planet|
@planets << planet
end
end
def to_s()
string = ""
@planets.each do |planet|
string += planet.to_s() + "\n"
end
end
end