forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 34
Queues - Erica Case - Solar System #27
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
Open
EricaJCasePhD
wants to merge
3
commits into
Ada-C7:master
Choose a base branch
from
EricaJCasePhD: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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,94 @@ | ||
| class Planet | ||
| attr_reader :name ,:travel_time, :length_of_day, :gravity_ratio, :mean_temperature# degrees C | ||
|
|
||
| def initialize(hash) | ||
| @name = hash[:planet].capitalize.to_sym | ||
| @gravity_ratio = hash[:gravity] / 9.8 | ||
| @length_of_day = hash[:day_length] | ||
| @mean_temperature = hash[:temp] | ||
| @travel_time = hash[:time] | ||
| end | ||
|
|
||
| def print_journey(weight) | ||
| puts "\nIt will take us #{@travel_time} to get to #{@name.capitalize}. The mean temperature will be #{@mean_temperature} degrees C, and one \"day\" \(planet rotation\) will be equal to #{@length_of_day} earth hours. You will weigh #{sprintf("%.1f", weight * @gravity_ratio)} pounds\n\n" | ||
| end | ||
| end | ||
|
|
||
| # source: http://nssdc.gsfc.nasa.gov/planetary/factsheet/ | ||
|
|
||
| # travel time source: http://www.astronomycafe.net/qadir/BackTo343.html | ||
|
|
||
| mercury = Planet.new(planet: "mercury", gravity: 3.7, day_length: 4222.6, temp: 167, time: "53 days") | ||
| venus = Planet.new(planet: "venus", gravity: 8.9, day_length: 2802, temp: 464,time: "100 days") | ||
| earth = Planet.new(planet: "earth", gravity: 9.8, day_length: 24.0, temp: 15, time: "0 days") | ||
| mars = Planet.new(planet: "mars", gravity: 1.6, day_length: 708.7,temp: -20, time: "210 days") | ||
| jupiter = Planet.new(planet: "jupiter", gravity: 3.7, day_length: 24.7, temp: -65, time: "1.9 years") | ||
| saturn = Planet.new(planet: "saturn", gravity: 23.1, day_length: 10.7,temp: -110, time: "7.3 years") | ||
| uranus = Planet.new(planet: "uranus", gravity: 9.0, day_length: 17.2, temp: -140, time: "0 days") | ||
| neptune = Planet.new(planet: "neptune", gravity: 8.7, day_length: 16.1, temp: -195, time:"11.4 years") | ||
| pluto = Planet.new(planet:"pluto", gravity: 11.0, day_length: 153.3, temp: -200, time: "15.1 years") | ||
|
|
||
|
|
||
|
|
||
| class SolarSystem | ||
| attr_reader :solar_system | ||
|
|
||
| def initialize | ||
| @solar_system = [] | ||
| end | ||
|
|
||
| def add_planet(planet) | ||
| if planet.is_a? (Array) | ||
|
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. Nice work supporting both an array and a single planet in the same method. |
||
| planet.each do |new_planet| | ||
| @solar_system << new_planet | ||
| end | ||
| else | ||
| @solar_system << planet | ||
| end | ||
| end | ||
|
|
||
| def print_all_planets | ||
| @solar_system.each do |new_planet| | ||
| print "#{new_planet.name}, " | ||
| end | ||
| end | ||
|
|
||
| def valid_planet?(destino) | ||
| @solar_system.each do |new_planet| | ||
| if new_planet.name.to_s == destino | ||
| puts "Yay! We are going to go to #{destino}" | ||
| return true | ||
| end | ||
| end | ||
| print "I'm sorry...I don't know how to get to #{destino}" | ||
| return false | ||
| end | ||
|
|
||
| def subset_planet(destino, wt) | ||
| @solar_system.each do |new_planet| | ||
| if new_planet.name.to_s == destino | ||
| new_planet.print_journey(wt) | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| galaxy = SolarSystem.new | ||
| galaxy.add_planet([mercury,venus, venus, earth, mars, jupiter, saturn, uranus, neptune, pluto]) | ||
| #################################################################################### | ||
|
|
||
| puts "\nHello there, astronaut friend! Let's journey to an exciting planet." | ||
|
|
||
| valid_planet = false | ||
| until valid_planet | ||
| print "\n\nWe can go to " | ||
| galaxy.print_all_planets | ||
| print " Where would you like to go? " | ||
| destination = gets.chomp.strip.capitalize | ||
| valid_planet = galaxy.valid_planet?(destination) | ||
| end | ||
|
|
||
| print "For purposes of shuttle safety, please enter your weight in pounds: " | ||
| weight = gets.chomp.to_i | ||
|
|
||
| galaxy.subset_planet(destination, weight) | ||
This file contains hidden or 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,95 @@ | ||
| # my very first class | ||
| class Planet | ||
| attr_reader :name ,:travel_time, :length_of_day, :gravity_ratio, :mean_temperature# degrees C | ||
|
|
||
| def initialize(hash) | ||
| @name = hash[:planet].capitalize.to_sym | ||
| @gravity_ratio = hash[:gravity] / 9.8 | ||
| @length_of_day = hash[:day_length] | ||
| @mean_temperature = hash[:temp] | ||
| @travel_time = hash[:time] | ||
| end | ||
|
|
||
| def print_journey(weight) | ||
| puts "\nIt will take us #{@travel_time} to get to #{@name.capitalize}. The mean temperature will be #{@mean_temperature} degrees C, and one \"day\" \(planet rotation\) will be equal to #{@length_of_day} earth hours. You will weigh #{sprintf("%.1f", weight * @gravity_ratio)} pounds\n\n" | ||
| end | ||
| end | ||
|
|
||
| # source: http://nssdc.gsfc.nasa.gov/planetary/factsheet/ | ||
|
|
||
| # travel time source: http://www.astronomycafe.net/qadir/BackTo343.html | ||
|
|
||
| mercury = Planet.new(planet: "mercury", gravity: 3.7, day_length: 4222.6, temp: 167, time: "53 days") | ||
| venus = Planet.new(planet: "venus", gravity: 8.9, day_length: 2802, temp: 464,time: "100 days") | ||
| earth = Planet.new(planet: "earth", gravity: 9.8, day_length: 24.0, temp: 15, time: "0 days") | ||
| mars = Planet.new(planet: "mars", gravity: 1.6, day_length: 708.7,temp: -20, time: "210 days") | ||
| jupiter = Planet.new(planet: "jupiter", gravity: 3.7, day_length: 24.7, temp: -65, time: "1.9 years") | ||
| saturn = Planet.new(planet: "saturn", gravity: 23.1, day_length: 10.7,temp: -110, time: "7.3 years") | ||
| uranus = Planet.new(planet: "uranus", gravity: 9.0, day_length: 17.2, temp: -140, time: "0 days") | ||
| neptune = Planet.new(planet: "neptune", gravity: 8.7, day_length: 16.1, temp: -195, time:"11.4 years") | ||
| pluto = Planet.new(planet:"pluto", gravity: 11.0, day_length: 153.3, temp: -200, time: "15.1 years") | ||
|
|
||
|
|
||
|
|
||
| class SolarSystem | ||
| attr_reader :solar_system | ||
|
|
||
| def initialize | ||
| @solar_system = [] | ||
| end | ||
|
|
||
| def add_planet(planet) | ||
| if planet.is_a? (Array) | ||
| planet.each do |new_planet| | ||
| @solar_system << new_planet | ||
| end | ||
| else | ||
| @solar_system << planet | ||
| end | ||
| end | ||
|
|
||
| def print_all_planets | ||
| @solar_system.each do |new_planet| | ||
| print "#{new_planet.name}, " | ||
| end | ||
| end | ||
|
|
||
| def valid_planet?(destino) | ||
| @solar_system.each do |new_planet| | ||
| if new_planet.name.to_s == destino | ||
| puts "Yay! We are going to go to #{destino}" | ||
| return true | ||
| end | ||
| end | ||
| print "I'm sorry...I don't know how to get to #{destino}" | ||
| return false | ||
| end | ||
|
|
||
| def subset_planet(destino, wt) | ||
| @solar_system.each do |new_planet| | ||
| if new_planet.name.to_s == destino | ||
| new_planet.print_journey(wt) | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| galaxy = SolarSystem.new | ||
| galaxy.add_planet([mercury,venus, venus, earth, mars, jupiter, saturn, uranus, neptune, pluto]) | ||
| #################################################################################### | ||
|
|
||
| puts "\nHello there, astronaut friend! Let's journey to an exciting planet." | ||
|
|
||
| valid_planet = false | ||
| until valid_planet | ||
| print "\n\nWe can go to " | ||
| galaxy.print_all_planets | ||
| print " Where would you like to go? " | ||
| destination = gets.chomp.strip.capitalize | ||
| valid_planet = galaxy.valid_planet?(destination) | ||
| end | ||
|
|
||
| print "For purposes of shuttle safety, please enter your weight in pounds: " | ||
| weight = gets.chomp.to_i | ||
|
|
||
| galaxy.subset_planet(destination, weight) |
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.
Good job re-working
Planet#initializeto take a hash.