Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions planet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
class Planet

#the accessor allows methods to be called upon.
attr_accessor :name, :trees, :hip_factor, :distance_from_sun, :number_of_moons, :number_of_rings, :number_of_martians, :solar_rotation

def initialize(planet_hash)
@name = planet_hash[:name]
@trees = planet_hash[:trees]
@hip_factor = planet_hash[:hip_factor]
@distance_from_sun = planet_hash[:distance_from_sun]
@number_of_moons = planet_hash[:number_of_moons]
@number_of_rings = planet_hash[:number_of_rings] || 4
@number_of_martians = planet_hash[:number_of_martians]
@solar_rotation = planet_hash[:solar_rotation]
end

def print_out
puts "#{@name}: A most fascinating planet. This planet has #{@trees} trees and a hip factor of #{@hip_factor}."
end
end

#create instances of Class planets

fremont = {

name: "Fremont",
trees: "10,000",
hip_factor: "so-so",
distance_from_sun: "30,000 miles",
number_of_moons: "12",
number_of_rings: "32",
number_of_martians: "32,000",
solar_rotation: "43",
}

ballard = {
name: "Ballard",
trees: "800",
hip_factor: "high",
distance_from_sun: "48,000",
number_of_moons: "2",
#commenting this out so that it will pull default value set above
# number_of_rings: "390",
number_of_martians: "43,000",
solar_rotation: "44",
}

cap_hill = {

name: "Capitol Hill",
trees: "10",
hip_factor: "very high",
distance_from_sun: "30,000 miles",
number_of_moons: "12",
number_of_rings: "32",
number_of_martians: "32,000",
solar_rotation: "43",
}

puts "Greetings, earthing! Welcome to the Seattle Solar System. There are three stellar planets that are in orbit in this solar system."

all_planets = []

# push instances of planets into the array #Planet.new runs the initializer
all_planets.push(Planet.new(fremont))
all_planets.push(Planet.new(ballard))
all_planets.push(Planet.new(cap_hill))

count = 1

puts "Which planet would you like to learn about? Type the number of your selection or type 'exit' to leave the program:"

result = "n"

while result != 0
count = 1
all_planets.each do |p|
puts "#{count}. #{p.name}"
count += 1
end
puts "#{count}. Exit"
result = gets.chomp.to_i
all_planets [result -1].print_out
end


#while continue == true
# if response =! "exit"
# puts "What planet do you want to learn about next?"


#end
48 changes: 48 additions & 0 deletions solar-system-progam.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require "./planet.rb"
require "./solar_system.rb"

#this is required even though Ruby can pull it from the planet.rb file. Anything that is a variable that's defined in 1 file will not exist in another file.
fremont = {

name: "Fremont",
trees: "10,000",
hip_factor: "so-so",
distance_from_sun: "30,000 miles",
number_of_moons: "12",
number_of_rings: "32",
number_of_martians: "32,000",
solar_rotation: "43",
}

ballard = {
name: "Ballard",
trees: "800",
hip_factor: "high",
distance_from_sun: "48,000",
number_of_moons: "2",
number_of_rings: "390",
number_of_martians: "43,000",
solar_rotation: "44",
}

cap_hill = {

name: "Capitol Hill",
trees: "10",
hip_factor: "very high",
distance_from_sun: "30,000 miles",
number_of_moons: "12",
number_of_rings: "32",
number_of_martians: "32,000",
solar_rotation: "43",
}

#this line will allow Ruby to populate "Seattle" as the info when it calls the name key in the hash of the solar_system file
s= Solarsystem.new({name: "Seattle"})
#this will allow Ruby to call upon the 'add_new_planet' method in the solar_system.rb file and populate a new planet with Fremont's info
s.add_new_planet(Planet.new(fremont))
s.add_new_planet(Planet.new(ballard))
s.add_new_planet(Planet.new(cap_hill))

#print out the planets method defined in the solary system file
puts s.planets
26 changes: 26 additions & 0 deletions solar-system.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#copy then contents of your solar system file here.


class Solarsystem
attr_accessor :name, :planets

def initialize(planet_hash)
@name = planet_hash[:name]
@planets = []
end
#this is what line 8 is doing.
# def planets
# return @planets
# end

def add_new_planet(planet)
@planets.push(planet)
end

def add_many_planets(many_planets)
many_planets.each do |planet|
@aplanets.push(planet)
end
end

end