Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ana Lisa Sutherland- Solar System- Octos C9 #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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 Ana_Lisa_Sutherland_Octos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
class Solar_S
attr_accessor :planets

def initialize (planets)
@planets = planets
end
# puts out list of just the planets in the solar system
def summary
x = 1
planet_sum = []
@planets.each do |planet|
planet_sum << "#{x}. #{planet.name}"
x += 1
end
return planet_sum
end
# allows user to pick a planet amongst the solar system
end

class Planet
## Create reader methods to give a user access to read the instance variables.
attr_accessor :name, :color, :order, :year_length, :distance_from_the_sun

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make these attr_accessor unless you specifically want to give users the ability to directly change the attributes using attr_reader would be more appropriate.

### Add an initialize method which takes several arguments
def initialize (name, color, order, year_length, distance_from_the_sun)
@name = name
@color = color
@order = order
@year_length = year_length
@distance_from_the_sun = distance_from_the_sun
end
# adds the new planet created by user to the whole solar system array
def planet_bio
planet_sum = []
planet_sum << "Name:#{name}\ncolor:#{color}\nOrder In Solar System:#{order}\nYear Length:#{year_length}\nDistance From The Sun:#{@distance_from_the_sun}"
return planet_sum
end
end

def new_planet
puts "What is the name of your planet?"
name = gets.chomp
puts "What color is your planet?"
color = gets.chomp
puts "What order is it in the solar system?"
order = gets.chomp
puts "How long is a year on your planet in Earth days?"
year_length = gets.chomp
puts "How far is the planet from our Sun?"
distance_from_the_sun = gets.chomp
x = Planet.new("#{name}","#{color}", "#{order}","#{year_length}", "#{distance_from_the_sun}")
return x
end

milky_way =
[
Planet.new("Mercury","silver","1st","87.96 Earth days","0.39 AU"),
Planet.new("Venus","yellow","2nd","224.68 Earth days","0.723 AU"),
Planet.new("Earth","Blue and Green","3rd","364 Earth days","92.95 M"),
Planet.new("Mars","Red","4th","687 Earth days","141.6M"),
Planet.new("Jupiter","Orange","5th","4,300 Earth days","483.8M"),
Planet.new("Saturn","Yellow","6th","11,000 Earth days","888.2M"),
Planet.new("Uranus","Teal","7th","31,000 Earth days","1.784 BM"),
Planet.new("Neptune","Blue","8th","60,200 Earth days","2.795 BM"),
Planet.new("Pluto","Grey","9th","90,500 Earth days","7.38 BM")
]
my_universe = Solar_S.new(milky_way)

puts "Welcome to the Planetarium.\nWould you like to view or add a planet?"
welcome_choice = gets.chomp.downcase

if welcome_choice == "view"
puts "Good choice, let me show you our planets"
puts my_universe.summary
puts "Which planet would you like to view?"
user_choice = gets.chomp
found = false
my_universe.planets.each do |planet|
if user_choice == planet.name
puts planet.planet_bio
found = true
end
end
if found == false
puts "This planet is not in our solar system."
end
elsif welcome_choice == "add"
puts "Ooo interesting, lets get some more info."
milky_way << new_planet
puts my_universe.summary
else
puts "Sorry, that does not make any sense."
end
94 changes: 94 additions & 0 deletions Solar_System_Ana_Lisa_Sutherland_Octo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
class Solar_S

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general don't use underscore (_) in Class names. Instead naming this class SolarSystem would be more appropriate.

attr_accessor :planets

def initialize (planets)
@planets = planets
end
# puts out list of just the planets in the solar system
def summary
x = 1
planet_sum = []
@planets.each do |planet|
planet_sum << "#{x}. #{planet.name}"
x += 1
end
return planet_sum
end
# allows user to pick a planet amongst the solar system
end

class Planet
## Create reader methods to give a user access to read the instance variables.
attr_accessor :name, :color, :order, :year_length, :distance_from_the_sun
### Add an initialize method which takes several arguments
def initialize (name, color, order, year_length, distance_from_the_sun)
@name = name
@color = color
@order = order
@year_length = year_length
@distance_from_the_sun = distance_from_the_sun
end
# adds the new planet created by user to the whole solar system array
def planet_bio
planet_sum = []
planet_sum << "Name:#{name}\nColor:#{color}\nOrder In Solar System:#{order}\nYear Length:#{year_length}\nDistance From The Sun:#{@distance_from_the_sun}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is planet_sum an array? Why not make it just a String? I don't think you gain anything making it an array.

return planet_sum
end
end

def new_planet
puts "What is the name of your planet?"
name = gets.chomp
puts "What color is your planet?"
color = gets.chomp
puts "What order is it in the solar system?"
order = gets.chomp
puts "How long is a year on your planet in Earth days?"
year_length = gets.chomp
puts "How far is the planet from our Sun?"
distance_from_the_sun = gets.chomp
x = Planet.new("#{name}","#{color}", "#{order}","#{year_length}", "#{distance_from_the_sun}")
return x
end

milky_way =
[
Planet.new("Mercury","silver","1st","87.96 Earth days","0.39 AU"),
Planet.new("Venus","yellow","2nd","224.68 Earth days","0.723 AU"),
Planet.new("Earth","Blue and Green","3rd","364 Earth days","92.95 M"),
Planet.new("Mars","Red","4th","687 Earth days","141.6M"),
Planet.new("Juipter","Orange","5th","4,300 Earth days","483.8M"),
Planet.new("Saturn","Yellow","6th","11,000 Earth days","888.2M"),
Planet.new("Uranus","Teal","7th","31,000 Earth days","1.784 BM"),
Planet.new("Neptune","Blue","8th","60,200 Earth days","2.795 BM"),
Planet.new("Pluto","Grey","9th","90,500 Earth days","7.38 BM")
]
my_universe = Solar_S.new(milky_way)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put this in some kind of loop so I could see or add multiple planets.

puts "Welcome to the Planetarium.\nWould you like to view or add a planet?"
welcome_choice = gets.chomp.downcase

if welcome_choice == "view"
puts "Good choice, let me show you our planets"
puts my_universe.summary

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the Planet name includes a number, it would be good to make sure that number works. Otherwise it's counterintuitive.

puts "Which planet would you like to view?"
user_choice = gets.chomp
found = false

my_universe.planets.each do |planet|
if user_choice == planet.name
puts planet.planet_bio
found = true
end
end

if found == false
puts "This planet is not in our solar system."
end
elsif welcome_choice == "add"
puts "Ooo interesting, lets get some more info."
milky_way << new_planet
puts my_universe.summary
else
puts "Sorry, that does not make any sense."
end