forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathSolarSystem.rb
More file actions
94 lines (76 loc) · 3.16 KB
/
SolarSystem.rb
File metadata and controls
94 lines (76 loc) · 3.16 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
class Planet
attr_reader :name ,:travel_time, :length_of_day, :gravity_ratio, :mean_temperature# degrees C
def initialize(hash)
@name = hash[:planet].capitalize.to_sym
@gravity_ratio = hash[:gravity] / 9.8
@length_of_day = hash[:day_length]
@mean_temperature = hash[:temp]
@travel_time = hash[:time]
end
def print_journey(weight)
puts "\nIt will take us #{@travel_time} to get to #{@name.capitalize}. The mean temperature will be #{@mean_temperature} degrees C, and one \"day\" \(planet rotation\) will be equal to #{@length_of_day} earth hours. You will weigh #{sprintf("%.1f", weight * @gravity_ratio)} pounds\n\n"
end
end
# source: http://nssdc.gsfc.nasa.gov/planetary/factsheet/
# travel time source: http://www.astronomycafe.net/qadir/BackTo343.html
mercury = Planet.new(planet: "mercury", gravity: 3.7, day_length: 4222.6, temp: 167, time: "53 days")
venus = Planet.new(planet: "venus", gravity: 8.9, day_length: 2802, temp: 464,time: "100 days")
earth = Planet.new(planet: "earth", gravity: 9.8, day_length: 24.0, temp: 15, time: "0 days")
mars = Planet.new(planet: "mars", gravity: 1.6, day_length: 708.7,temp: -20, time: "210 days")
jupiter = Planet.new(planet: "jupiter", gravity: 3.7, day_length: 24.7, temp: -65, time: "1.9 years")
saturn = Planet.new(planet: "saturn", gravity: 23.1, day_length: 10.7,temp: -110, time: "7.3 years")
uranus = Planet.new(planet: "uranus", gravity: 9.0, day_length: 17.2, temp: -140, time: "0 days")
neptune = Planet.new(planet: "neptune", gravity: 8.7, day_length: 16.1, temp: -195, time:"11.4 years")
pluto = Planet.new(planet:"pluto", gravity: 11.0, day_length: 153.3, temp: -200, time: "15.1 years")
class SolarSystem
attr_reader :solar_system
def initialize
@solar_system = []
end
def add_planet(planet)
if planet.is_a? (Array)
planet.each do |new_planet|
@solar_system << new_planet
end
else
@solar_system << planet
end
end
def print_all_planets
@solar_system.each do |new_planet|
print "#{new_planet.name}, "
end
end
def valid_planet?(destino)
@solar_system.each do |new_planet|
if new_planet.name.to_s == destino
puts "Yay! We are going to go to #{destino}"
return true
end
end
print "I'm sorry...I don't know how to get to #{destino}"
return false
end
def subset_planet(destino, wt)
@solar_system.each do |new_planet|
if new_planet.name.to_s == destino
new_planet.print_journey(wt)
end
end
end
end
galaxy = SolarSystem.new
galaxy.add_planet([mercury,venus, venus, earth, mars, jupiter, saturn, uranus, neptune, pluto])
####################################################################################
puts "\nHello there, astronaut friend! Let's journey to an exciting planet."
valid_planet = false
until valid_planet
print "\n\nWe can go to "
galaxy.print_all_planets
print " Where would you like to go? "
destination = gets.chomp.strip.capitalize
valid_planet = galaxy.valid_planet?(destination)
end
print "For purposes of shuttle safety, please enter your weight in pounds: "
weight = gets.chomp.to_i
galaxy.subset_planet(destination, weight)