-
Notifications
You must be signed in to change notification settings - Fork 49
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
Leaves - Dominique #39
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Wave 3 | ||
# Since wave 3 required replacing the driver code in our main method, | ||
# I choose to create another file for Wave 3. | ||
|
||
require_relative "planet" | ||
require_relative "solar_system" | ||
|
||
def main | ||
# Wave 3 | ||
solar_system = SolarSystem.new("Sun") | ||
saturn = Planet.new("Saturn", "Blue", "13.e56", "4.98e33", "Has a ring around it") | ||
pluto = Planet.new("Pluto", "Very Blue", "45.e87", "2.34e8", "Isn't actually a planet") | ||
neptune = Planet.new("Neptune", "Very Very Blue", "87.e45", "3.45e3", "Really cold") | ||
|
||
solar_system.add_planet(saturn) | ||
solar_system.add_planet(pluto) | ||
solar_system.add_planet(neptune) | ||
|
||
def planet_details(solar_system) | ||
puts "Which planet would you like to learn about?" | ||
planet = gets.chomp | ||
found_planet = solar_system.find_planet_by_name(planet) | ||
return found_planet.summary | ||
end | ||
|
||
def add_planet(solar_system) | ||
planet_details_array = [] | ||
# puts "What are the details of this planet? Provide the following. \nname: \ncolor: \nmass_kg: \ndistance: \nfun fact:" | ||
puts "What is the name of this planet?" | ||
planet_details_array.push(gets.chomp) | ||
puts "What is the color of this planet?" | ||
planet_details_array.push(gets.chomp) | ||
puts "What is the mass_kg of this planet?" | ||
planet_details_array.push(gets.chomp) | ||
puts "What is the distance of this planet from the Sun?" | ||
planet_details_array.push(gets.chomp) | ||
puts "What is a fun fact about this planet?" | ||
planet_details_array.push(gets.chomp) | ||
planet = Planet.new(planet_details_array[0], planet_details_array[1], planet_details_array[2], planet_details_array[3], | ||
planet_details_array[4]) | ||
return solar_system.add_planet(planet) | ||
end | ||
|
||
user_input = "A" | ||
|
||
while user_input == "A" || user_input == "B" || user_input == "C" | ||
puts "What would you like to do next? \nA: List planets \nB: Planet Details \nC: Add Planet \nD: Exit Program" | ||
user_input = gets.chomp | ||
case user_input | ||
when "A" | ||
puts solar_system.list_planets | ||
when "B" | ||
puts planet_details(solar_system) | ||
when "C" | ||
add_planet(solar_system) | ||
when "D" | ||
user_input = "D" | ||
end | ||
end | ||
end | ||
|
||
main |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Wave 1 | ||
require_relative "planet" | ||
require_relative "solar_system" | ||
|
||
def main | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was expecting you to overwrite this file with Wave 3. It did me a scare when there was no loop! Remember, git will track changes, so as long as you commit, nothing is truly lost! |
||
jupiter = Planet.new("Jupiter", "Orange", "5.972e23", "1.94e8", "Has a red eye full of storms") | ||
earth = Planet.new("Earth", "Blue", "34.e39", "14", "Only planet with life") | ||
mercury = Planet.new("Mercury", "Red", "35.e39", "10", "Hottest Planet") | ||
venus = Planet.new("Venus", "Brown", "39.e39", "20", "2nd Hottest Planet") | ||
mars = Planet.new("Mars", "Brown-Orange", "40.e27", "30", "Super Rocky") | ||
|
||
puts "\n#{earth.summary}" | ||
|
||
# Wave 2 | ||
solar_system = SolarSystem.new("Sun") | ||
solar_system.add_planet(mercury) | ||
solar_system.add_planet(venus) | ||
solar_system.add_planet(earth) | ||
solar_system.add_planet(mars) | ||
solar_system.add_planet(jupiter) | ||
|
||
list = solar_system.list_planets | ||
puts list | ||
|
||
found_planet = solar_system.find_planet_by_name("eArTh") | ||
puts "\n#{found_planet}" | ||
puts "\n#{found_planet.summary}" | ||
end | ||
|
||
main | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Wave 1 | ||
class Planet | ||
def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact) | ||
@name = name | ||
@color = color | ||
@mass_kg = mass_kg | ||
@distance = distance_from_sun_km | ||
@fun_fact = fun_fact | ||
end | ||
|
||
attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact | ||
|
||
def summary | ||
return "Planet #{@name} is #{@color} and #{@fun_fact}." | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
# Wave 2 | ||
|
||
class SolarSystem | ||
attr_reader = :star_name, :planets | ||
|
||
def initialize(star_name) | ||
@star_name = star_name | ||
@planets = [] | ||
end | ||
|
||
def add_planet(planet) | ||
@planets.push(planet) | ||
end | ||
|
||
def list_planets | ||
planet_array = [] | ||
star_name = "\nPlanets orbiting #{@star_name}" | ||
@planets.each_with_index do |planet, index| | ||
planet_array.push("#{index + 1}. #{planet.name}") | ||
end | ||
return "#{star_name} \n#{planet_array.join("\n")}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice! |
||
end | ||
|
||
def find_planet_by_name(planet_string) | ||
@planets.each do |planet| | ||
if planet.name.upcase == planet_string.upcase | ||
return planet | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't define methods inside other methods unless you are doing something very fancy! This can cause weird problems, and can make debugging a nightmare!
planet_details
andadd_planet
are both defined inside ofmain
!