forked from Ada-C12/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplanet.rb
27 lines (22 loc) · 881 Bytes
/
planet.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
# Each instance of this class will keep track of information about a single planet.
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
until @mass_kg > 0
puts "Mass kilograms must be greater than 0! Please insert a new number:"
@mass_kg = gets.chomp.to_i
end
until @distance_from_sun_km > 0
puts "Distance from the sun must be greater than 0! Please insert a new number:"
@distance_from_sun_km = gets.chomp.to_i
end
end
def summary
return "#{@name}: It is the color #{@color}, it has a mass kg of #{@mass_kg}, it is #{@distance_from_sun_km} km from the sun, and #{@fun_fact}!"
end
end