-
Notifications
You must be signed in to change notification settings - Fork 48
Sockets-Bita #48
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-Bita #48
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,55 @@ | ||
| require_relative "planet" | ||
| require_relative "solar_system" | ||
|
|
||
| def main | ||
| solar_system = SolarSystem.new("Sun") | ||
|
|
||
| jupiter = Planet.new("Jupiter", "multicolor", "1.89e27", "7.78e8", "Has more than 75 moons!") | ||
| mars = Planet.new("Mars", "red", "6.41e23", "2.27e8", "Had water in the Ancient Past!") | ||
| earth = Planet.new("Earth", "blue-green", "5.972e24", "1.496e8", "Only planet known to support life") | ||
|
|
||
| solar_system.add_planets(earth) | ||
| solar_system.add_planets(jupiter) | ||
| solar_system.add_planets(mars) | ||
|
|
||
| x = 1 | ||
| while x != 2 | ||
| puts "What would you like to do?" | ||
| puts "1. List planet" | ||
| puts "2. Exit" | ||
| puts "3. Planet details" | ||
| puts "4. Add planet" | ||
| x = gets.chomp.to_i | ||
| if x == 1 | ||
| list = solar_system.list_planets | ||
| puts list | ||
| elsif x == 3 | ||
|
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. The user should be able to type a command like "list planets" or "quit" for these, not a number. Also, why are your numbered options out of order? That makes this code just a bit more confusing. |
||
| puts "Which Planet would you like to know about?" | ||
| planet = gets.chomp.downcase | ||
| found_planet = solar_system.find_planet_by_name(planet) | ||
| puts found_planet.summary | ||
| elsif x == 4 | ||
| puts "What is the name of the name of the planet you want to add?" | ||
| name = gets.chomp | ||
| puts "What is the color of your 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. The code to view planet details and to add a planet ends up being pretty big. It might be wise to isolate each of these in its own method. 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. Also, this is a big long block of code with no breaks. You should split it up using empty lines. |
||
| color = gets.chomp | ||
| puts "What is the weight in Kg?" | ||
| mass = gets.chomp.to_f | ||
| puts "What is the distance from the Sun?" | ||
| distance = gets.chomp.to_f | ||
| puts "Tell me a fun fact about this planet:" | ||
| fun_fact = gets.chomp | ||
| name = Planet.new("#{name}", "#{color}", "#{mass}", "#{distance}", "#{fun_fact}") | ||
| solar_system.add_planets(name) | ||
| end | ||
| end | ||
|
|
||
| #list = solar_system.list_planets | ||
|
|
||
| # found_planet = solar_system.find_planet_by_name("Earth") | ||
| # puts found_planet | ||
| # puts found_planet.summary | ||
| #puts list | ||
| end | ||
|
|
||
| main | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| 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 | ||
| end | ||
|
|
||
| earth = Planet.new("Earth", "blue-green", "5.972e24", "1.496e8", "Only planet known to support life") | ||
| puts earth.name | ||
| puts earth.fun_fact | ||
|
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. Here you are creating an instance of In general, please remove all debugging work before submitting your assignment. |
||
|
|
||
| def summary | ||
| return "Planet #{name} is #{color}, it weigh #{mass_kg}kg and it's #{distance_from_sun_km} km away from Sun, something fun about this planet is #{fun_fact}" | ||
| end | ||
| end | ||
|
|
||
| #puts earth.fun_fact | ||
| #earth.color = "pink" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| class SolarSystem | ||
| attr_reader :star_name, :planet | ||
|
|
||
| def initialize(star_name) | ||
| @planets = [] | ||
| @star_name = star_name | ||
| end | ||
|
|
||
| def add_planets(planet) | ||
| @planets.push(planet) | ||
| 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. Small nitpick: the spec asked for a method named Since the method only adds one planet at a time, |
||
|
|
||
| def find_planet_by_name(name) | ||
| #raise ArgumentError unless @planet.include?(name.capitalize) | ||
| @planets.find { |planet| planet.name.downcase == name.downcase } | ||
| 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. Good use of an enumerable here. |
||
|
|
||
| def list_planets | ||
| rotating_planets = @planets.map.with_index { |item, index| | ||
| "#{index + 1}" + "." + item.name | ||
| } | ||
| puts "Planets orbiting Sun are: " | ||
| return rotating_planets | ||
|
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. Instead of |
||
| 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.
I don't know that I like the variable name
xhere - could you call this something more descriptive? Maybeuser_choice?