forked from AdaGold/solar-system
-
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 - Amy #26
Open
aphunk
wants to merge
7
commits into
Ada-C11:master
Choose a base branch
from
aphunk:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Sockets - Amy #26
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
26c1b17
Wave 1 - defined Planet class
aphunk a113bd1
added main.rb
aphunk f504011
refactored main method to match requirements
aphunk 3fd1a97
finished wave 3
aphunk ea9b284
completed wave 3
aphunk f2f46ab
finished wave 3
aphunk c953792
refactored 'learn about planet code' to be dynamic
aphunk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require_relative "planet" | ||
require_relative "solar_system" | ||
require "pry" | ||
|
||
def main | ||
solar_system = SolarSystem.new("Phunghoule") | ||
|
||
bebop = Planet.new(name: "Bebop", color: "gray", mass_kg: 5, distance_from_sun_km: 2.2, fun_fact: "Bebop's nickname is Mrs. Tubbins!") | ||
ninou = Planet.new(name: "Ninou", color: "black", mass_kg: 3, distance_from_sun_km: 2.2, fun_fact: "Ninou is the best planet ever!") | ||
andrew = Planet.new(name: "Andrew", color: "white", mass_kg: 91, distance_from_sun_km: 3, fun_fact: "Andrew is full of gas") | ||
|
||
solar_system.add_planet(bebop) | ||
solar_system.add_planet(ninou) | ||
solar_system.add_planet(andrew) | ||
|
||
loop do | ||
puts "Choose your next adventure: " | ||
puts "\ntype LIST to see a list of all planets, " | ||
puts "type LEARN to learn about the planets," | ||
puts "type ADD to create your own planet, or" | ||
puts "type EXIT to quit" | ||
|
||
selection = gets.chomp.downcase | ||
|
||
case selection | ||
when "exit" | ||
puts "Goodbye." | ||
exit | ||
when "list" | ||
puts "#{solar_system.list_planets}" | ||
when "learn" | ||
puts "#{solar_system.list_planets}" | ||
puts "Type the name of the planet you want to learn about: " | ||
learn_choice = gets.chomp.capitalize! | ||
|
||
solar_system.planets.each_with_index do |planet, index| | ||
puts "#{planet.name}" | ||
if planet.name == learn_choice | ||
puts "#{planet.summary}" | ||
end | ||
end | ||
when "add" | ||
solar_system.add_planet_details | ||
puts "Thanks! Your planet has been added to the solar system: " | ||
puts "#{solar_system.list_planets}" | ||
end | ||
end | ||
end | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Planet | ||
attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact | ||
|
||
def initialize(name: "", color: "", mass_kg: 0, distance_from_sun_km: 0, fun_fact: "") | ||
@name = name | ||
@color = color | ||
@mass_kg = mass_kg | ||
@distance_from_sun_km = distance_from_sun_km | ||
@fun_fact = fun_fact | ||
end | ||
|
||
def summary | ||
return "The planet, #{@name} is #{@color} in color, its mass is #{@mass_kg}kg, has a distance of #{@distance_from_sun_km}km from sun, fun fact: #{@fun_fact}" | ||
end | ||
end | ||
|
||
ARIEL = Planet.new(name: "Ariel", color: "blue-ish", mass_kg: 6455783, distance_from_sun_km: 308546069, fun_fact: "Ariel has an extensive network of medical-related industries.") | ||
|
||
LONDINIUM = Planet.new(name: "Londinium", color: "green-ish", mass_kg: 1236620, distance_from_sun_km: 1346380, fun_fact: "Londinium is where the Parliament is housed.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
class SolarSystem | ||
attr_reader :star_name, :planets | ||
|
||
def initialize(star_name) | ||
@star_name = star_name | ||
@planets = [] | ||
end | ||
|
||
def add_planet_details | ||
puts "Enter the new planet's name: " | ||
name = gets.chomp.capitalize | ||
puts "Color of the planet: " | ||
color = gets.chomp.downcase | ||
puts "Mass in kilograms: " | ||
mass = gets.chomp.to_i | ||
puts "Distance from the sun in kg" | ||
distance = gets.chomp.to_i | ||
puts "A fun fact about the planet: " | ||
fun_fact = gets.chomp.capitalize | ||
|
||
new_planet = Planet.new(name: "#{name}", color: "#{color}", mass_kg: mass, distance_from_sun_km: distance, fun_fact: "#{fun_fact}") | ||
|
||
add_planet(new_planet) | ||
end | ||
|
||
def add_planet(planet) | ||
@planets.push(planet) | ||
return planet | ||
end | ||
|
||
def list_planets | ||
list_of_planets = "Planets orbiting #{@star_name}" | ||
@planets.each_with_index do |planet, index| | ||
list_of_planets += "\n#{index + 1}: #{planet.name}" | ||
end | ||
return list_of_planets | ||
end | ||
|
||
def find_planet_by_name(planet_name) | ||
@planets.each do |planet| | ||
if planet.name.capitalize == 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. Is there an enumerable method you could use to make this a little cleaner? |
||
end | ||
end | ||
return nil | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Please remove debug output (like line 37) before submitting projects.