forked from Ada-C5/Solar-System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplanet.rb
More file actions
87 lines (73 loc) · 2.83 KB
/
planet.rb
File metadata and controls
87 lines (73 loc) · 2.83 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
# Solar System 2.22.16 Justine Winnie
# Let's make a planetary system!
#
# Baseline
# Create a Planet class with a name attribute.
# You should be able to instantiate a new Planet object with an associated name.
#Wave 1
# Give each instance of Planet at least five attributes.
# Allow these attributes to be set using a hash in initialize.
#Additionals
# Give each planet a rate of solar rotation
# Give each planet a @distance_from_the_sun attribute
# Write a program that asks for user input to query the planets:
# First, ask the user to select a planet they'd like to learn about.
# Present the user with a list of planets from which they can choose. Something like:
# 1. Mercury, 2. Venus, 3. Earth, 4. Secret Earth, 5. Mars, 6. Jupiter, ... 13. Exit
# Provide the user with well formatted information about the planet (diameter, mass, number of moons, primary export, etc.)
# Then ask the user for another planet.
# Wave 2
# Create a SolarSystem class that has an attribute planets that has zero to many Planet instances.
#There are a few different options for how to associate the planets with your solar system:
# Initialize the list of planets in the constructor of the solar system
# Create a method that adds a single planet to a solar system
# Create a method that adds a list of planets to the existing list of planets
class Planet
def initialize(planetdata)
@name = planetdata[:name] #string
@presence_of_water = planetdata[:water] #Boolean
@taco_tuesday = planetdata[:taco_tuesday] #Boolean
@atmosphere = planetdata[:atmosphere] #string
@avg_temperature = planetdata[:avg_temperature] #float
@solar_rotation = planetdata[:solar_rotation] #float
@distance_from_the_sun = planetdata[:distance_from_the_sun] #float - expressed in miles because AMERICA
end
def taco_please
puts @taco_tuesday
end
def name
puts @name
end
end
earth = Planet.new(name: "earth", taco_tuesday: "hells yes", distance_from_the_sun: 93000000)
mars = Planet.new(name: "mars", taco_tuesday: "no", distance_from_the_sun: 141633260)
unicornia = Planet.new(name: "unicornia", avg_temperature: "delightful", distance_from_the_sun: "pink clouds")
allplanets = [earth, mars, unicornia]
class SolarSystem
def initialize
@planets = []
end
def add_planet
puts "What planet do you want to add?"
planetoadd = gets.chomp
@planets << planetoadd
end
def add_array(thearray)
@planets.push(thearray)
@planets.flatten
end
end
# def list_planets
# @planets.each do
# puts @planets[:name]
# end
# end
# def add_planet_list
# puts "Enter a planet you'd like to add and hit enter."
# planet = gets.chomp
#
# until planet.include? "All done!"
# puts "Enter another planet to add, followed by the enter key. If you're done, enter 'All done!'"
# planet = gets.chomp
# @planets << planet
# end