forked from Ada-C10/Solar-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
73 lines (48 loc) · 1.74 KB
/
main.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
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
require_relative 'lib/planet'
require_relative 'lib/solar_system'
#planet details method
def list_details(solar_system, planet_name)
if planet_name
planet = solar_system.find_planet_by_name(planet_name)
return planet.summary
end
end
def add_planet(solar_system, planet_name, color, mass_kg, distance_from_sun_km, fun_fact)
planet_name = Planet.new(planet_name, color, mass_kg, distance_from_sun_km, fun_fact)
solar_system.add_planet(planet_name)
end
def main
solar_system = SolarSystem.new('Sol')
earth = Planet.new('Earth', 'blue-green', 5.972e24, 1.496e8, 'Only planet known to support life')
mars = Planet.new('Mars', 'red', 10, 100, 'Martians')
venus = Planet.new('Venus', 'russet', 7, 23, 'Serena')
solar_system.add_planet(earth)
solar_system.add_planet(mars)
solar_system.add_planet(venus)
input = "START"
while input != "EXIT"
puts "\nChoose an option: \n\n1. LIST PLANETS\n2. PLANET DETAILS\n3. ADD A PLANET\n4. EXIT"
input = gets.chomp.upcase
if input.include?("LIST")
puts solar_system.list_planets
elsif input.include?("DETAILS")
puts "Which planet?"
planet_name = gets.chomp.upcase
puts list_details(solar_system, planet_name)
elsif input.include?("ADD")
#THROW ERROR IF THEY PUT ANYTHING BUT FLOAT/INT FOR NUMBER
puts "\nPlanet name: "
planet_name = gets.chomp
puts "\nPlanet color: "
color = gets.chomp
puts "\nPlanet mass (kg): "
mass_kg = gets.to_i
puts "\nPlanet distance (km): "
distance_from_sun_km = gets.to_i
puts "\nFun fact about #{planet_name}: "
fun_fact = gets.chomp
puts add_planet(solar_system, planet_name, color, mass_kg, distance_from_sun_km, fun_fact)
end
end
end
main