forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 34
Queues - Janice Lichtman - Solar System (2 files) #21
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
J-C-L
wants to merge
3
commits into
Ada-C7:master
Choose a base branch
from
J-C-L: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 @@ | ||
| I'm a fake solar system |
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,79 @@ | ||
| #Janice Lichtman's Solar System Wave 1 | ||
|
|
||
| #I'm submitting this as a separate file since the user interaction loops aren't relevant to the functionality of wave 2, and it seems easier for you to read this way. | ||
|
|
||
| class Planet | ||
| attr_accessor :name, :mass, :number_of_moons, :length_of_day, :distance_from_sun, :mean_temperature, :solar_revolution_rate | ||
|
|
||
| def initialize (address_hash) | ||
| @name = address_hash[:name] | ||
| @mass = address_hash[:mass] # * 10**24 in kg | ||
| @number_of_moons = address_hash[:number_of_moons] | ||
| @length_of_day = address_hash[:length_of_day] #in hours | ||
| @distance_from_sun = address_hash[:distance_from_sun] # * 10**6 in km | ||
| @mean_temperature = address_hash[:mean_temperature] #in C | ||
| @solar_revolution_rate = address_hash[:solar_revolution_rate] #length of 1 of that planet's "years" measured in earth days | ||
| end | ||
| end | ||
|
|
||
|
|
||
| earth = Planet.new(name: "Earth", mass: 5.97, number_of_moons: 1, length_of_day: 24, distance_from_sun: 149.6, mean_temperature: 15, solar_revolution_rate: 365.26) | ||
| mercury = Planet.new(name: "Mercury", mass: 0.330, number_of_moons: 0, length_of_day: 422.6, distance_from_sun: 57.9, mean_temperature: 167, solar_revolution_rate: 87.97) | ||
| venus = Planet.new(name: "Venus", mass: 4.87, number_of_moons: 0, length_of_day: 2802.0, distance_from_sun: 108.2, mean_temperature: 464, solar_revolution_rate: 224.7) | ||
| mars = Planet.new(name: "Mars", mass: 0.642, number_of_moons: 2, length_of_day: 24.7, distance_from_sun: 227.9, mean_temperature: -65, solar_revolution_rate: 686.98) | ||
| jupiter = Planet.new(name: "Jupiter", mass: 1989, number_of_moons: 67, length_of_day: 9.9, distance_from_sun: 778.6, mean_temperature: -110, solar_revolution_rate: 4332.82) | ||
| saturn = Planet.new(name: "Saturn", mass: 568, number_of_moons: 62, length_of_day: 10.7, distance_from_sun: 1433.5, mean_temperature: -140, solar_revolution_rate: 10755.7) | ||
| uranus = Planet.new(name: "Uranus", mass: 86.8, number_of_moons: 27, length_of_day: 17.2, distance_from_sun: 2872.5, mean_temperature: -195, solar_revolution_rate: 30687.15) | ||
| neptune = Planet.new(name: "Neptune", mass: 102, number_of_moons: 14, length_of_day: 16.1, distance_from_sun: 4495.1 , mean_temperature: -200, solar_revolution_rate: 60190.03) | ||
|
|
||
| #Array of the planet objects. Inherently stored as ids. | ||
| planets = [mercury, venus, earth, mars, jupiter, saturn, uranus, neptune] | ||
|
|
||
| planet_names =[] | ||
|
|
||
| #Creating an array of the planet names | ||
| planets.each do |planet| | ||
| planet_names << planet.name | ||
| end | ||
|
|
||
| #Loop to continue offering planet information to the user. | ||
| keep_going = true | ||
| while keep_going | ||
|
|
||
| puts "What planet would you like to learn about?\nYour options are:" | ||
| planet_names.each do |name| | ||
| print "#{name} " | ||
| end | ||
| puts "" | ||
|
|
||
| chosen_planet = gets.chomp.capitalize | ||
|
|
||
| until planet_names.include? (chosen_planet) | ||
| puts "Silly goose, that's not a planet! Try again:" | ||
| chosen_planet = gets.chomp.capitalize | ||
| end | ||
|
|
||
| puts "Great choice! Here's some information about the planet #{chosen_planet}:" | ||
| puts "Mass: #{planets[planet_names.index(chosen_planet)].mass} x 10^24 kg" | ||
| puts "Number of moons: #{planets[planet_names.index(chosen_planet)].number_of_moons}" | ||
| puts "Length of a day: #{planets[planet_names.index(chosen_planet)].length_of_day} hours" | ||
| puts "Distance from the sun: #{planets[planet_names.index(chosen_planet)].distance_from_sun} x 10^6 km" | ||
| puts "Mean temperature: #{planets[planet_names.index(chosen_planet)].mean_temperature} degrees Celcius" | ||
| puts "Length of 1 year (in earth days): #{planets[planet_names.index(chosen_planet)].solar_revolution_rate} days" | ||
| puts | ||
|
|
||
|
|
||
| puts "Would you like to learn about another planet? (yes or no)" | ||
|
|
||
| more = gets.chomp.downcase | ||
| until (more =="yes" || more == "no") | ||
| puts "Please answer yes or no.\nWould you like to learn about another planet?" | ||
| more = gets.chomp.downcase | ||
| end | ||
|
|
||
| if more == "yes" | ||
| keep_going = true | ||
| else | ||
| keep_going = false | ||
| end | ||
| end |
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,85 @@ | ||
| #Janice Lichtman's Solar System Wave 2 | ||
|
|
||
| class SolarSystem | ||
| attr_accessor :planets, :solar_system_age | ||
|
|
||
| def initialize | ||
| @planets=[] | ||
| @solar_system_age | ||
| end | ||
|
|
||
| #Adds a single planet to a solar system | ||
| def add_a_planet (planet) | ||
| @planets << planet | ||
| end | ||
|
|
||
| #Adds a list of planets to a solar system | ||
| def add_many_planets (planets) #here planets is an array | ||
| planets.each do |planet| | ||
| @planets << planet | ||
| end | ||
| end | ||
|
|
||
|
|
||
| #Gives a list of the local year of every planet in the solar system | ||
| def planet_ages | ||
| puts "The ages of the planets are:" | ||
| @planets.each do |planet| | ||
| puts "#{planet.name}: #{'%.2f' % planet.local_year(@solar_system_age)} years" | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
||
| class Planet | ||
| attr_accessor :name, :mass, :number_of_moons, :length_of_day, :distance_from_sun, :mean_temperature, :solar_revolution_rate | ||
|
|
||
| def initialize (address_hash) | ||
| @name = address_hash[:name] | ||
| @mass = address_hash[:mass] # * 10**24 in kg | ||
| @number_of_moons = address_hash[:number_of_moons] | ||
| @length_of_day = address_hash[:length_of_day] #in hours | ||
| @distance_from_sun = address_hash[:distance_from_sun] # * 10**6 in km | ||
| @mean_temperature = address_hash[:mean_temperature] #in C | ||
| @solar_revolution_rate = address_hash[:solar_revolution_rate] #length of 1 of that planet's "years" measured in earth days | ||
| end | ||
|
|
||
| #Calculates the local year of a planet based on the age of that planet's solar system | ||
| def local_year(solar_system_age) | ||
| (solar_system_age) / @solar_revolution_rate | ||
| end | ||
|
|
||
| end | ||
|
|
||
| earth = Planet.new(name: "Earth", mass: 5.97, number_of_moons: 1, length_of_day: 24, distance_from_sun: 149.6, mean_temperature: 15, solar_revolution_rate: 365.26) | ||
| mercury = Planet.new(name: "Mercury", mass: 0.330, number_of_moons: 0, length_of_day: 422.6, distance_from_sun: 57.9, mean_temperature: 167, solar_revolution_rate: 87.97) | ||
| venus = Planet.new(name: "Venus", mass: 4.87, number_of_moons: 0, length_of_day: 2802.0, distance_from_sun: 108.2, mean_temperature: 464, solar_revolution_rate: 224.7) | ||
| mars = Planet.new(name: "Mars", mass: 0.642, number_of_moons: 2, length_of_day: 24.7, distance_from_sun: 227.9, mean_temperature: -65, solar_revolution_rate: 686.98) | ||
| jupiter = Planet.new(name: "Jupiter", mass: 1989, number_of_moons: 67, length_of_day: 9.9, distance_from_sun: 778.6, mean_temperature: -110, solar_revolution_rate: 4332.82) | ||
| saturn = Planet.new(name: "Saturn", mass: 568, number_of_moons: 62, length_of_day: 10.7, distance_from_sun: 1433.5, mean_temperature: -140, solar_revolution_rate: 10755.7) | ||
| uranus = Planet.new(name: "Uranus", mass: 86.8, number_of_moons: 27, length_of_day: 17.2, distance_from_sun: 2872.5, mean_temperature: -195, solar_revolution_rate: 30687.15) | ||
| neptune = Planet.new(name: "Neptune", mass: 102, number_of_moons: 14, length_of_day: 16.1, distance_from_sun: 4495.1 , mean_temperature: -200, solar_revolution_rate: 60190.03) | ||
|
|
||
| #Array of the planet objects. Inherently stored as ids. | ||
| planets_to_add = [mercury, venus, earth, mars, jupiter, saturn, uranus, neptune] | ||
|
|
||
|
|
||
| our_solar_system = SolarSystem.new | ||
| #Populatng the solar system! | ||
| our_solar_system.add_many_planets(planets_to_add) | ||
|
|
||
| our_solar_system.solar_system_age = 1.68 * 10**11 | ||
|
|
||
|
|
||
| #Determining the distance between two planets | ||
| def distance_between_planets (planet1, planet2) | ||
| distance = (planet1.distance_from_sun.to_f - planet2.distance_from_sun.to_f).abs | ||
| puts "The distance between #{planet1.name} and #{planet2.name} is #{'%.2f' % distance} x 10^6km." | ||
| distance | ||
| end | ||
|
|
||
| #Demonstration of finding the distance between 2 planets | ||
| distance_between_planets(mars,venus) | ||
|
|
||
| #Demonstration of finding the ages of the planets in our_solar_system | ||
| our_solar_system.planet_ages | ||
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.