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

Earth - Kal (re-submitted) #51

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

def get_new_user_planet
puts "Let's add a new planet! Please provide the following info:"
puts "Planet name:"
name = gets.chomp
puts "Planet color:"
color = gets.chomp
puts "Planet's mass in kilograms:"
mass = gets.chomp
puts "Planet's distance from in the sun in kilometers:"
distance = gets.chomp
puts "Fun fact about planet:"
fun_fact = gets.chomp
puts ""

new_planet = Planet.new(name, color, mass, distance, fun_fact)

return new_planet
end

def get_user_planet_choice
puts "Planet name?"

planet_choice = gets.chomp
puts ""

return planet_choice
end

def main
solar_system = SolarSystem.new('Sol')
earth = Planet.new('Earth', 'blue-green', 5.972e24, 1.496e8, 'Only planet known to support life')
jupiter = Planet.new('Jupiter', 'orange-yellow', 50.24e34 , 5.496e8, 'Fastest spinning planet in the Solar System')

solar_system.add_planet(earth)
solar_system.add_planet(jupiter)


puts "*💫* WELCOME TO THE SOLAR SYSTEM DATABASE *💫*_\n"
puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
puts "\n What would you like to do?\n"
puts "1. List Planets\n"
puts "2. Get Planet Information\n"
puts "3. Enter New Planet\n"
# puts "4. Intergalactic Distance Calculator\n"
puts "4. Exit\n"
puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

loop do
print "\nEnter database selection: "
choice = gets.chomp.to_s

case choice

when "1"
puts solar_system.list_planets

when "2"
puts "Enter Planet name:"
planet_name = get_user_planet_choice
found_planet = solar_system.find_planet_by_name(planet_name)

if (found_planet)
puts found_planet.summary
else
puts "I couldn't find a planet by the name #{planet_name}.\n\n"
end

when "3"
puts "What planet would you like to add? "
solar_system.add_planet(get_new_user_planet)
puts "\n...Entered into system. Thank You."

# when "4"
# planet_1 = get_user_planet_choice
# planet_2 = get_user_planet_choice
#
# puts solar_system.distance_between(planet_1, planet_2) #!!!!!

when "4"
exit
else
puts "\nError. Invalid input."
end
end
end


main


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

def initialize (name, color, mass_kg, distance_from_sun, fun_fact)
@name = name.capitalize
@color = color
@mass_kg = mass_kg
@distance_from_sun = distance_from_sun
@fun_fact = fun_fact
end

def summary
return "Planet #{@name} is the color #{@color}. It's mass is #{@mass_kg} kg and it's distance from the sun is #{@distance_from_sun}. Fun fact => #{@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'

class SolarSystem
attr_reader :star_name, :planets

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

def add_planet(new_planet)
@planets << new_planet
end

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

def find_planet_by_name(planet_name)
@planets.each do |planet|
if planet.name == planet_name.capitalize
return planet
end
end
return raise ArgumentError, 'Planet not in star system'
end

# def distance_between(planet_1, planet_2) #OPTIONAL
# return ((planet_1.distance_from_sun) - (planet_2.distance_from_sun)).abs #still have to make method for returning distance form sun
# end

end