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

Solar-System #49

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
6 changes: 6 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/solar-system.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require_relative 'planet.rb'
require_relative 'solar_system.rb'

# create_a_solar_system

def main
# The solar system
addi = SolarSystem.new('P.O.M.')
phoenix = Planet.new('Phoenix', 'fire red', 1, 2, '2 years old')
justice = Planet.new('Justice', 'golden brown', 2, 3, '800 years old')
taylor = Planet.new('Taylor', 'sky blue', 3,4, 'deserved better')

addi.add_planet(phoenix)
addi.add_planet(justice)
addi.add_planet(taylor)

found_planet = addi.find_planet_by_name('Phoenix')

found_planet.name
found_planet.summary

# Control loop w/ 2 options
loop = true
while loop
puts "Would you like to see a list of planets? Y/N."
user_input = gets.chomp.upcase
if user_input == 'Y'
puts addi.list_planets
elsif user_input == 'N'
puts "Ok. Would you like to EXIT then? Y/N."
user_input_2 = gets.chomp.upcase
if user_input_2 == 'Y'
loop = false
elsif
puts "Guess we'll figure something else out."
end
elsif user_input != 'Y' || user_input != 'N'
raise ArgumentError, 'Only answers accepted are Y or N. Exiting.'
end
# ask user if they'd like to see a list of planets or exit the program
# add planet_details option - should call separate method - they name a planet
# it delivers details
# add_planet : ask user for planet details,
# create new instance of planet, add planet to solar system
end
end

# def create_and_add_planet
# puts "Would you like to build a planet? Y/N"
# builder = gets.chomp.upcase
# if builder == 'Y'
# puts "Give me a planet name:"
# planet_name = gets.chomp.capitalize
# puts "Give me #{planet_name}'s color:"
# planet_color = gets.chomp.downcase
# puts "Now what's the weight in kg?"
# planet_km = gets.chomp.to_i
# puts "How far is the planet from the sun in km?"
# planet_distance = gets.chomp.to_i
# puts "Last thing, give it one fun fact:"
# fun = gets.chomp.to_s
#
# new_planet = Planet.new(planet_name, planet_color, planet_km, planet_distance, fun)
# addi.add_planet(new_planet)
# 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, distance_from_sun_km, fun_fact)
@name = name
@color = color
@mass_kg = mass_kg
@distance_from_sun_km = distance_from_sun_km
@fun_fact = fun_fact
@summary = summary
end

def summary
return "#{@name} is #{@color} weighs #{@mass_kg}kg sits
#{@distance_from_sun_km}km from the sun & FUN FACT
it's only #{@fun_fact}!!!"
end
end
36 changes: 36 additions & 0 deletions solar_system.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require_relative 'planet.rb'

# attr_reader :star_name
# attr_reader :planets

class SolarSystem

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

def add_planet(planet)
@planets << planet
return @planet
end

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

def find_planet_by_name(planet_name)
@planets.each do |planet|
if planet_name.downcase == planet.name.downcase
return planet
end
end
return "No."
end
end