-
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 - Grace #40
base: master
Are you sure you want to change the base?
Sockets - Grace #40
Changes from all commits
a08d1d2
3fe3937
800a9af
b7e2e8b
eb24312
bd10d6f
55c2de0
2d129b4
c54eb55
90ffcd9
d35a93e
c82f4dd
139928d
8b56841
4fb796c
2937959
4d47d7e
640474d
c4aa48f
a106899
c214304
a96b0f7
aa35e37
aa4ca3f
f625e3b
c884b3c
ef5a972
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,53 @@ | ||
require_relative "planet" | ||
require_relative "solar_system" | ||
|
||
def main | ||
solar_system = SolarSystem.new("Sol") | ||
|
||
elvis = Planet.new("Elvis", "shiny", 159, 20, "recorded more than 600 songs, but did not write any of them", 3.5) | ||
hank_sr = Planet.new("Hank Sr", "white as hell", 72, 30, "recorded 14 songs as his alter ego, Luke the Drifter", 4.5) | ||
dolly = Planet.new("Dolly", "canary yellow", 52, 18, "once entered a Dolly look-alike drag queen contest and lost", 4.8) | ||
patsy = Planet.new("Patsy", "chesnut", 70, 40, "enjoys walking after midnight", 3.4) | ||
garth = Planet.new("Garth", "off-white", 83, 45, "is responsible for the the most insufferable variety of country boi", 4.6) | ||
johnny = Planet.new("Johnny", "coal black", 86, 5, "was a campaigner for Native American rights", 3.6) | ||
reba = Planet.new("Reba", "red", 60, 10, "is the only country female solo act to have a No. 1 hit in four straight decades", 5.0) | ||
willie = Planet.new("Willie", "old", 70, 7, "ran into a burning house to save his pound of Columbian grass", 3.8) | ||
|
||
solar_system.add_planet(elvis) | ||
solar_system.add_planet(hank_sr) | ||
solar_system.add_planet(dolly) | ||
solar_system.add_planet(patsy) | ||
solar_system.add_planet(garth) | ||
solar_system.add_planet(johnny) | ||
solar_system.add_planet(reba) | ||
|
||
puts "Country Music Planetary Menu\n" | ||
puts "1. List Planets\n" | ||
puts "2. Planet Information\n" | ||
puts "3. Add a New Planet\n" | ||
puts "4. Distance Calculator\n" | ||
puts "5. Exit\n" | ||
|
||
loop do | ||
"Please enter your selection from the above options." | ||
input = gets.chomp.to_s | ||
case | ||
when input == "1" | ||
puts solar_system.list_planets | ||
when input == "2" | ||
planet = solar_system.get_planet_name | ||
puts planet.summary | ||
when input == "3" | ||
solar_system.get_info_new_planet | ||
puts "\n...Entered into system. Thank You." | ||
when input == "4" | ||
solar_system.find_distance_between | ||
when input == "5" | ||
exit | ||
when input =~ /[[:alpha:]]/ | ||
puts "\nYour response was invalid" | ||
end | ||
end | ||
end | ||
|
||
main |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
|
||
class Planet | ||
attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact, :twang_level, :likelihood_to_be_loved_by_yanks | ||
|
||
def initialize(name, color, mass, distance_from_sun_km, fun_fact, twang_level) | ||
@name = name.capitalize | ||
@color = color | ||
@mass_kg = mass_kg | ||
@distance_from_sun_km = distance_from_sun_km | ||
@fun_fact = fun_fact | ||
@twang_level = twang_level | ||
if mass <= 0 | ||
raise ArgumentError, "Planet mass must be larger than 0" | ||
end | ||
if distance_from_sun_km <= 0 | ||
raise ArgumentError, "Planet distance must be larger than 0" | ||
end | ||
end | ||
|
||
def summary | ||
puts "The planet #{@name} is the color #{@color} has a mass of #{@mass} kg, and is #{@distance_from_sun_km} km from the sun. | ||
It #{@fun_fact}, and is know to have a twang level of #{@twang_level} out of 5." | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
|
||
class SolarSystem | ||
attr_reader :solar_system_name, :planets | ||
|
||
def initialize(solar_system_name) | ||
@solar_system_name = solar_system_name | ||
@planets = [] | ||
end | ||
|
||
def add_planet(new_planet) | ||
@planets << new_planet | ||
end | ||
|
||
def get_info_new_planet | ||
print "\nWhat is your new Planet's name?" | ||
planet_name = gets.chomp.to_s | ||
print "\nWhat is #{planet_name}'s color?" | ||
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 have a lot of code that interacts with the user here, which makes me think this method might fit better in |
||
color = gets.chomp.to_s | ||
print "\nWhat is the distance of planet from #{solar_system_name}(km): " | ||
distance = gets.chomp.to_f | ||
print "\nMass of #{planet_name}(kg): " | ||
mass = gets.chomp.to_f | ||
print "\nInteresting fact about #{planet_name}: " | ||
fun_fact = gets.chomp.to_s | ||
print "\nPlease rate the planet's twang on a scale of 0-5.0 #{planet_name}: " | ||
twang_level = gets.chomp.to_f | ||
|
||
new_planet = Planet.new(planet_name, color, distance, mass, fun_fact, twang_level) | ||
|
||
add_planet(new_planet) | ||
print "\nGenerating new data" | ||
end | ||
|
||
def list_planets | ||
list = "\nPlanets in the Country Music Universe:\n" | ||
@planets.each_with_index do |planet, index| | ||
index += 1 | ||
list += "#{index}. #{planet.name}\n" | ||
end | ||
return list | ||
end | ||
|
||
def find_planet_by_name(planet_name) | ||
@planets.each do |planet| | ||
if planet.name == planet_name.capitalize | ||
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. This code has a bug! Your parameter (which should be the name of a planet) is called Probably the parameter should be called 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. Dan, thank you for your feedback! I will take a look at this over the weekend and refactor. |
||
end | ||
end | ||
raise ArgumentError, "Planet does not exist in the Country Music Hall of Planets" | ||
end | ||
|
||
def get_planet_name | ||
print "\nEnter planet name: " | ||
planet = gets.chomp.to_s | ||
return find_planet_by_name(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. This method also might fit better in |
||
end | ||
|
||
def get_planet_distance(name) | ||
@planets.each do |planet| | ||
if planet.name == name.capitalize | ||
return planet.distance | ||
end | ||
end | ||
raise ArgumentError, "Planet does not exist in the Country Music Hall of Planets" | ||
end | ||
|
||
def find_distance_between | ||
planet1 = get_planet_name | ||
planet2 = get_planet_name | ||
distance = (planet1.distance_from_sun_km) - (planet2.distance_from_sun_km) | ||
puts "\nDistance between #{planet1.name} and #{planet2.name}: #{distance.abs} km." | ||
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 return a number here 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.
Option 3 does not work - the method on
SolarSystem
isget_info_new_planet
, notadd_a_planet
.