-
Notifications
You must be signed in to change notification settings - Fork 48
Sockets-Chantal #47
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
base: master
Are you sure you want to change the base?
Sockets-Chantal #47
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,52 @@ | ||
| require_relative "Planet" | ||
| require_relative "Solar_System" | ||
|
|
||
| def main | ||
| solar_system = SolarSystem.new("Solus") | ||
| neptune = Planet.new("Neptune", "blue", 1.02E26, 4.495E9, "greek god of the sea Poseidons planet") | ||
| mars = Planet.new("Mars", "red", 6.3E23, 227.9E9, "greek god of war Aries planet") | ||
| venus = Planet.new("Venus", "pink", 4.86E24, 108E9, "greek goddess of love Aphrodites planet") | ||
| solar_system.add_planet(neptune) | ||
| solar_system.add_planet(mars) | ||
| solar_system.add_planet(venus) | ||
| list = solar_system.list_planets | ||
|
|
||
| found_planet = solar_system.find_planet_by_name("Venus") | ||
|
|
||
| input = "" | ||
|
|
||
| until input == "exit" | ||
| puts "what would you like to do? list planets, planet details, add planet, exit" | ||
| input = gets.chomp | ||
| if input == "list planets" | ||
| list = solar_system.list_planets | ||
| puts list | ||
| elsif input == "planet details" | ||
| puts "what planet do you want to learn about?" | ||
| user_add_planet = gets.chomp | ||
| chosen_planet = solar_system.find_planet_by_name(user_add_planet) | ||
| puts chosen_planet.summary | ||
| elsif input == "add planet" | ||
| planet_new = add_new_planet | ||
| solar_system.add_planet(add_new_planet) | ||
| else | ||
| puts "toodles!" | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def add_new_planet | ||
| puts "What is the name of the planet?" | ||
| name = gets.chomp.capitalize | ||
| puts "What color is the planet?" | ||
|
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 like that you broke this out into a separate method - good organization! |
||
| color = gets.chomp.downcase | ||
| puts "What is the planet's mass in kilograms?" | ||
| mass_kg = gets.chomp.to_f | ||
| puts "What is the planet's distance from the sun" | ||
| distance_from_sun_km = gets.chomp.to_i | ||
| puts "What is a fun fact about the planet?" | ||
| fun_fact = gets.chomp | ||
| new_planet = Planet.new(name, color, mass_kg, distance_from_sun_km, fun_fact) | ||
| end | ||
|
|
||
| main | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| class Planet | ||
| 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 | ||
| end | ||
|
|
||
| def name | ||
| return @name | ||
| end | ||
|
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. You should use the helper methods ( |
||
|
|
||
| def name=(name) | ||
| @name = name | ||
| end | ||
|
|
||
| def color | ||
| return @color | ||
| end | ||
|
|
||
| def color=(color) | ||
| @color = color | ||
| end | ||
|
|
||
| def mass_kg | ||
| return @mass_kg | ||
| end | ||
|
|
||
| def mass_kg=(mass_kg) | ||
| @mass_kg = mass_kg | ||
| end | ||
|
|
||
| def distance_from_sun_km | ||
| return @distance_from_sun_km | ||
| end | ||
|
|
||
| def distance_from_sun_km=(distance_from_sun_km) | ||
| @distance_from_sun_km = distance_from_sun_km | ||
| end | ||
|
|
||
| def fun_fact | ||
| return @fun_fact | ||
| end | ||
|
|
||
| def fun_fact=(fun_fact) | ||
| @fun_fact = fun_fact | ||
| end | ||
|
|
||
| def summary | ||
| return "The planet #{@name} is the color #{@color}. A neat fact about the planet: #{@fun_fact}." | ||
| end | ||
| end | ||
|
|
||
| # Load Planet into pry: | ||
| # $ pry -r ./planet.rb | ||
| mars = Planet.new("Mars", "red", 6.3E23, 227.9E9, "greek god of war Aries planet") | ||
| venus = Planet.new("Venus", "pink", 4.86E24, 108E9, "greek goddess of love Aphrodites planet") | ||
| jupiter = Planet.new("Neptune", "blue", 1.02E26, 4.495E9, "greek god of the sea Poseidons planet") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| class SolarSystem | ||
| def initialize(star_name) | ||
| @star_name = star_name | ||
| @planets = [] | ||
| end | ||
|
|
||
| def star_name | ||
| return @star_name | ||
| end | ||
|
|
||
| def planets | ||
| return @planets | ||
| end | ||
|
|
||
| def add_planet(planet) | ||
| @planets.push(planet) | ||
| end | ||
|
|
||
| def list_planets | ||
| str = "Planets orbiting #{@star_name}\n" | ||
| @planets.each_with_index do |planet, index| | ||
| str += "#{index + 1}. #{planet.name}\n" | ||
| end | ||
| return str | ||
| end | ||
|
|
||
| def find_planet_by_name(planet_name) | ||
| @planets.each do |planet| | ||
| if planet_name.upcase == planet.name.upcase | ||
| return planet | ||
|
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. Is there an enumerable method you could use for this? |
||
| end | ||
| end | ||
| return nil | ||
| 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.
On line 30 you call
add_new_planetand assign it to theplanet_newvariable. Then on line 31, instead of usingplanet_new, you calladd_new_planetagain! That means the user has to enter all this info twice.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.
THANK YOU for pointing that out. that was driving me bananas i couldnt figure out why it asked twice.