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
Binary file added .DS_Store
Binary file not shown.
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.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

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.

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


def create_solar_system #factory setup the initial state
solar_system = SolarSystem.new('Sol')

#name, color, mass_kg, distance_from_sun_km, fun_fact
earth = Planet.new('Earth', 'Blue', '3.09822e21', '1.12343e6', 'it is nicknamed the blueberry')
mercury = Planet.new('Mercury', 'Grey', '3.29903e2', '1.349900e2', 'it has the most craters in the solar system')
moon = Planet.new( 'Moon', 'Golden', '1.2332e2', '1.12332e1', 'It has active tectonic systems')
venus = Planet.new('Venus', 'orange', '2.323442e2', '3.44211e2', 'A day on Venus is longer than a year on earth')

solar_system.add_planet(earth)
solar_system.add_planet(mercury)
solar_system.add_planet(moon)
solar_system.add_planet(venus)

return solar_system

end

def ask_user_choice
puts "Welcome to the Planet Info session! What would you like to do?"
options = ["list planets", "planet details", "add planet", "exit"]
options.each do |choice|
puts "*#{choice}"
end
user_choice = gets.chomp
return user_choice
end

def ask_user_planet_choice
puts "What is the name of the planet you wish to learn about?"

planet_choice = gets.chomp

return planet_choice
end

def ask_user_new_planet_details
puts "Let's make up a new planet! Give me the details!:"
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 main
my_solar_system = create_solar_system
while ask_user_choice != "exit"

user_choice = ask_user_choice

case user_choice.upcase
when "LIST PLANETS"
puts my_solar_system.list_planets

when "PLANET DETAILS"
planet_name = ask_user_planet_choice
found_planet = my_solar_system.find_my_planet_by_name(found)
if (found_planet) == true
puts found_planet.summary
else
puts "I couldn't find a planet by the name #{planet_name}.\n"
end

when "ADD PLANET"
new_planet = ask_user_new_planet_details
my_solar_system.add_planet(new_planet)

when "EXIT"
exit
else
puts "Hmm...I did not get that. Try again?"
end
end

end
main #why do we invoke main as the last line of your program?
28 changes: 28 additions & 0 deletions planet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#wave1
#each instance of this class will keep track of information about a single planet

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

# if @mass_kg < 0 || @distance_from_sun_km < 0
# raise ArgumentError, "Invalid Entry"
# end
end

def summary
#This method should return (not puts) a string containing a nicely-formatted description of the planet.
# Exercise your summary method in the main method.
description = "This #{@name} with the color #{@color} has a mass of #{@mass_kg} and is #{@distance_from_sun_km}from
the sun. A fun fact about it is: #{@fun_fact}"
return description
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 @@
#wave2
#SolarSystem is responsible for keeping track of a collection of instances of Planet.
class SolarSystem # has to have a star and the planets
attr_reader :star_name, :planet

def initialize(star_name)
@star_name = star_name # the sun
@planets = [] #will store an array of planets
end

# will take an instance of Planet as a parameter and add it to the list of planets.
def add_planet(planet)
@planets << planet
end

# will return (not puts) a string containing a list of all the planets in the system.
def list_planets
list = "Planets orbiting #{@star_name}:\n"
@planets.each do |planet|
list += "* #{planet.name}\n"
end
list += "\n"
return list
end

#the find_planet_by_name returns the correct instance of Planet
# Note: We can use planets, @planets, or self.planets
def find_my_planet_by_name(found)#.downcase
found_planet = planets.find do |planet|
planet.name.upcase == found.upcase
end
return found_planet

end

end