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

Sockets - Amy #26

Open
wants to merge 7 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
50 changes: 50 additions & 0 deletions main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require_relative "planet"
require_relative "solar_system"
require "pry"

def main
solar_system = SolarSystem.new("Phunghoule")

bebop = Planet.new(name: "Bebop", color: "gray", mass_kg: 5, distance_from_sun_km: 2.2, fun_fact: "Bebop's nickname is Mrs. Tubbins!")
ninou = Planet.new(name: "Ninou", color: "black", mass_kg: 3, distance_from_sun_km: 2.2, fun_fact: "Ninou is the best planet ever!")
andrew = Planet.new(name: "Andrew", color: "white", mass_kg: 91, distance_from_sun_km: 3, fun_fact: "Andrew is full of gas")

solar_system.add_planet(bebop)
solar_system.add_planet(ninou)
solar_system.add_planet(andrew)

loop do
puts "Choose your next adventure: "
puts "\ntype LIST to see a list of all planets, "
puts "type LEARN to learn about the planets,"
puts "type ADD to create your own planet, or"
puts "type EXIT to quit"

selection = gets.chomp.downcase

case selection
when "exit"
puts "Goodbye."
exit
when "list"
puts "#{solar_system.list_planets}"
when "learn"
puts "#{solar_system.list_planets}"
puts "Type the name of the planet you want to learn about: "
learn_choice = gets.chomp.capitalize!

solar_system.planets.each_with_index do |planet, index|
puts "#{planet.name}"
if planet.name == learn_choice

Choose a reason for hiding this comment

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

Please remove debug output (like line 37) before submitting projects.

puts "#{planet.summary}"
end
end
when "add"
solar_system.add_planet_details
puts "Thanks! Your planet has been added to the solar system: "
puts "#{solar_system.list_planets}"
end
end
end

main
19 changes: 19 additions & 0 deletions planet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Planet
attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact

def initialize(name: "", color: "", mass_kg: 0, distance_from_sun_km: 0, fun_fact: "")
@name = name
@color = color
@mass_kg = mass_kg
@distance_from_sun_km = distance_from_sun_km
@fun_fact = fun_fact
end

def summary
return "The planet, #{@name} is #{@color} in color, its mass is #{@mass_kg}kg, has a distance of #{@distance_from_sun_km}km from sun, fun fact: #{@fun_fact}"
end
end

ARIEL = Planet.new(name: "Ariel", color: "blue-ish", mass_kg: 6455783, distance_from_sun_km: 308546069, fun_fact: "Ariel has an extensive network of medical-related industries.")

LONDINIUM = Planet.new(name: "Londinium", color: "green-ish", mass_kg: 1236620, distance_from_sun_km: 1346380, fun_fact: "Londinium is where the Parliament is housed.")
47 changes: 47 additions & 0 deletions solar_system.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
class SolarSystem
attr_reader :star_name, :planets

def initialize(star_name)
@star_name = star_name
@planets = []
end

def add_planet_details
puts "Enter the new planet's name: "
name = gets.chomp.capitalize
puts "Color of the planet: "
color = gets.chomp.downcase
puts "Mass in kilograms: "
mass = gets.chomp.to_i
puts "Distance from the sun in kg"
distance = gets.chomp.to_i
puts "A fun fact about the planet: "
fun_fact = gets.chomp.capitalize

new_planet = Planet.new(name: "#{name}", color: "#{color}", mass_kg: mass, distance_from_sun_km: distance, fun_fact: "#{fun_fact}")

add_planet(new_planet)
end

def add_planet(planet)
@planets.push(planet)
return planet
end

def list_planets
list_of_planets = "Planets orbiting #{@star_name}"
@planets.each_with_index do |planet, index|
list_of_planets += "\n#{index + 1}: #{planet.name}"
end
return list_of_planets
end

def find_planet_by_name(planet_name)
@planets.each do |planet|
if planet.name.capitalize == planet_name.capitalize
return planet

Choose a reason for hiding this comment

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

Is there an enumerable method you could use to make this a little cleaner?

end
end
return nil
end
end