-
Notifications
You must be signed in to change notification settings - Fork 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
Sockets - Kate N #29
base: master
Are you sure you want to change the base?
Sockets - Kate N #29
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 "terminal-table" | ||
require_relative "planet" | ||
require_relative "solar_system" | ||
|
||
def main | ||
solar_system = SolarSystem.new("A Wrinkle in Time") | ||
|
||
camazotz = Planet.new(“Camazotz”, “red”, 68.9, 22.777, “Ruled by a disembodied brain”) | ||
ixchel = Planet.new(“Ixchel”, “pink”, 49, 10.8E9, “Inhabited by sightless creatures”) | ||
uriel = Planet.new(“Uriel”, “blue”, 10, 411.5E1, “Lots of extremely tall mountains”) | ||
|
||
solar_system.add_planet(camazotz) | ||
solar_system.add_planet(ixchel) | ||
solar_system.add_planet(uriel) | ||
|
||
directions = "" | ||
|
||
until directions == "exit" | ||
puts "Please enter list planets to see all the planets, planet details to learn more about each planet, or add planet to enter a new planet. | ||
directions = gets.chomp.downcase | ||
if directions == "list planets"EXIT | ||
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. More syntax errors: missing and end-quote on line 19, and an extra |
||
list = solar_system.list_planets | ||
puts list | ||
elsif directions == "planet details" | ||
puts "Please enter the planet name you'd like to see details for?" | ||
show_details = gets.chomp | ||
found_planet = solar_system.find_planet_by_name(show_details) | ||
puts found_planet.summary | ||
elsif directions == "add planet" | ||
planet_new = add_new_planet | ||
solar_system.add_planet(planet_new) | ||
else | ||
puts "\nThanks!" | ||
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've broken this functionality out as a separate method, and that you've kept it here in |
||
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 A Wrinkle in Time?" | ||
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,20 @@ | ||
require "terminal-table" | ||
|
||
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 | ||
|
||
attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact | ||
|
||
def summary | ||
table = Terminal::Table.new :headings => ["Name", "Color", "Mass (kg)", "Distance From Sun (km)", "Fun Fact"] do |t| | ||
t.add_row [@name, @color, @mass_kg, @distance_from_sun_km, @fun_fact] | ||
end | ||
return table | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class SolarSystem | ||
attr_reader :star_name, :planets | ||
|
||
def initialize(star_name) | ||
@star_name = star_name | ||
@planets = [] | ||
end | ||
|
||
def add_planet(planet) | ||
@planets << planet | ||
end | ||
|
||
def list_planets | ||
list = "Planets orbiting #{@star_name}:\n" | ||
@planets.each_with_index do |planets, number| | ||
item = "#{number + 1}. #{planets.name}\n" | ||
list += item | ||
end | ||
return list | ||
end | ||
|
||
def find_planet_by_name(find_planet) | ||
repeat_name = @planets.find { |planet_name| planet_name.name == find_planet.capitalize } | ||
return repeat_name | ||
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'm not convinced by these variable names. What about something like this: def find_planet_by_name(name)
found_planet = @planets.find { |planet| planet.name == name.capitalize }
return found_planet
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.
Your
main.rb
file had a bunch of weird syntax errors. It somehow ended up with a bunch of angle quotes (“”
) instead of straight quotes ("
), which very much confuses the Ruby interpreter. You can see here that the syntax highlighting doesn't understand what's going on.The only way I've seen this happen is via saving code in a Google doc or word doc or similar application, and then copy/pasting it into your editor directly.
This problem was relatively easy to fix, but isn't one I would expect you to be hitting. I have two asks for you here: