forked from Ada-C9/Solar-System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNew_wave3.rb
More file actions
104 lines (98 loc) · 3.31 KB
/
New_wave3.rb
File metadata and controls
104 lines (98 loc) · 3.31 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
95
96
97
98
99
100
101
102
103
104
#Create Plant class
class Planet
attr_reader :planet,:desc,:orbit,:diameter,:rotate,:distance
def initialize(planet,desc,orbit,diameter,rotate,distance)
@planet = planet
@desc = desc
@orbit =orbit
@diameter=diameter
@rotate = rotate
@distance = distance
end
def planet_attributes
attributes = "Planet: #{@planet}\nDesc: #{@desc}\nOrbit: #{@orbit}\nDiameter: #{@diameter}\nYear Length: #{@rotate}\nDistance from Sun: #{@distance}\n"
return attributes
end
end
#Create Solar System Class
class SolarSystem
attr_accessor :planet
def initialize(planet)
@planet = planet
end
def add_planet(new_planet)
@planet<<new_planet
end
def return_planets
list_of_planets = []
@planet.each do |planet|
list_of_planets << "#{@planet.index(planet)+1}. #{planet}"
end
return list_of_planets
end
#Calling Planet Class to print attributes from SolarSystem class
def check
choice=gets.chomp.to_i
if choice == 1
element = Planet.new("Mercury","Smallest planet","47.8km/sec","4878km","87.97days","70millionkm")
b =element.planet_attributes
return b
elsif choice == 2
element = Planet.new("Mars","Fourth planet in Solar System","35km/sec","12,100km","243days","108million km")
b = element.planet_attributes
return b
elsif choice == 3
element = Planet.new("Venus","Second planet in Solar system","70km/sec","11000km","345days","234million km")
b = element.planet_attributes
return b
elsif choice == 4
element = Planet.new("Earth","Third planet in Solar System","88km/sec","234334km","365days","12million km")
b = element.planet_attributes
return b
end
end
end
#Method to add new planet from user input
def create_planet_userinput(new_planet,new_planet_desc,new_planet_orbit,new_planet_diameter,
new_planet_rotate,new_planet_distance)
new_element = Planet.new(new_planet,new_planet_desc,new_planet_orbit,new_planet_diameter,
new_planet_rotate,new_planet_distance)
return new_element
end
#Array of planets
planet_array = %w[Mercury Mars Venus Earth]
planet_list = SolarSystem.new(planet_array)
#Start of user interface
print"Welcome to the Solar System\n"
answer = "y"
while answer.include?("y")
print"Select a planet to know the details:\n"
puts planet_list.return_planets
puts planet_list.check
print "Do you know about other planets (y/n)?"
answer = gets.chomp
end
#New planet routine
print "Do you want to add a new planet (y/n)"
answer1 = gets.chomp
if answer1 == "y"
print "Please enter the planet name"
new_planet = gets.chomp
print "Enter the desc"
new_planet_orbit = gets.chomp
print"orbit"
new_planet_desc = gets.chomp
print "Enter the diameter "
new_planet_diameter = gets.chomp
print " orbital speed "
new_planet_rotate = gets.chomp
print "enter the distance"
new_planet_distance = gets.chomp
new_planet1 = create_planet_userinput(new_planet, new_planet_desc,new_planet_orbit,new_planet_diameter,new_planet_rotate,new_planet_distance)
print new_planet1.planet_attributes
planet_array << new_planet
puts planet_list.return_planets
#print planet_list
elsif answer1 == "n"
print "Thanks for looking"
end