forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 34
Queues - Andrea Valliere - solar_system.rb #37
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
avalliere
wants to merge
2
commits into
Ada-C7:master
Choose a base branch
from
avalliere: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 1 commit
Commits
Show all changes
2 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,72 @@ | ||
| # Create Planet class with name and several other attributes | ||
| class Planet | ||
| attr_accessor :name, :order_from_sun, :moon_count, :diameter, :day_length, :atmosphere_contents | ||
|
|
||
| def initialize(planets_hash) | ||
| @name = planets_hash[:name] | ||
| @order_from_sun = planets_hash[:order_from_sun] | ||
| @moon_count = planets_hash[:moon_count] | ||
| @diameter = planets_hash[:diameter] | ||
| @day_length = planets_hash[:day_length] | ||
| @atmosphere_contents = planets_hash[:atmosphere_contents] | ||
| end | ||
| end | ||
|
|
||
| # Create a SolarSystem class that has an attribute "planets" that has zero to many Planet instances | ||
| class SolarSystem | ||
| attr_accessor :planets | ||
|
|
||
| def initialize | ||
| @planets = [] | ||
| end | ||
|
|
||
| # Create methods that 1.) add a single planet to a solar system 2.) add a list of planets to an existing list of planets | ||
|
|
||
| def add_planet(name, order_from_sun, moon_count, diameter, day_length, atmosphere_contents) | ||
| @planets.push(name, order_from_sun, moon_count, diameter, day_length, atmosphere_contents) | ||
| end | ||
|
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 sure |
||
|
|
||
| def add_many(planets_array) | ||
| planets_array.each do |entry| | ||
| @planets.push(entry) | ||
| end | ||
|
|
||
| end | ||
| end | ||
|
|
||
| # Add a planet to a new SolarSystem instance using methods from the SolarSystem class | ||
|
|
||
| kuiper_belt = SolarSystem.new | ||
| kuiper_belt.add_planet("Pluto", "9th", "1", "2,234 miles", "7 hours, 8 minutes", "Nitrogen and Helium") | ||
|
|
||
| # Instantiate new planet objects with an associated name. These are pushing to an array so they can be easily moved to a SolarSystem class using one of the methods defined in that class | ||
|
|
||
| planets = [] | ||
|
|
||
| planets << earth = Planet.new(name: "Earth", order_from_sun: "3rd", moon_count: "1", diameter: "7,926 miles", day_length: "23 hours, 56 minutes", atmosphere_contents: "Nitrogen and Oxygen") | ||
|
|
||
| planets << mercury = Planet.new(name: "Mercury", order_from_sun: "1st", moon_count: "0", diameter: "3,031 miles", day_length: "59 days", atmosphere_contents: "Sodium and Helium") | ||
|
|
||
| planets << venus = Planet.new(name: "Venus", order_from_sun: "2nd", moon_count: "0", diameter: "7,521 miles", day_length: "243 days", atmosphere_contents: "Carbon Dioxide and Nitrogen") | ||
|
|
||
| planets << mars = Planet.new(name: "Mars", order_from_sun: "4th", moon_count: "2", diameter: "4,222 miles", day_length: "24 hours, 37 minutes", atmosphere_contents: "Carbon Dioxide and Argon") | ||
|
|
||
| planets << jupiter = Planet.new(name: "Jupiter", order_from_sun: "5th", moon_count: "66", diameter: "88,846 miles", day_length: "9 hours, 55 minutes", atmosphere_contents: "Hydrogen, and Helium") | ||
|
|
||
| planets << saturn = Planet.new(name: "Saturn", order_from_sun: "6th", moon_count: "62", diameter: "74,900 miles", day_length: "10 hours, 39 minutes", atmosphere_contents: "Hydrogen, and Helium") | ||
|
|
||
| planets << uranus = Planet.new(name: "Uranus", order_from_sun: "7th", moon_count: "27", diameter: "31,763 miles", day_length: "17 hours, 14 minutes", atmosphere_contents: "Hydrogen, Helium, and Methane") | ||
|
|
||
| planets << neptune = Planet.new(name: "Neptune", order_from_sun: "8th", moon_count: "13", diameter: "30,779 miles", day_length: "16 hours, 7 minutes", atmosphere_contents: "Hydrogen, Helium, and Methane") | ||
|
|
||
| # This pushes the planets array into a new SolarSystem class. | ||
| our_solar_system = SolarSystem.new | ||
| our_solar_system.add_many(planets) | ||
|
|
||
| # Display information about all of the planets of our solar system | ||
| puts "THE PLANETS of our SOLAR SYSTEM" | ||
| puts | ||
|
|
||
| planets.each do |instance| | ||
| puts "#{instance.name.upcase} is the #{instance.order_from_sun} planet from the sun. #{instance.name} has #{instance.moon_count} moon(s) and a diameter of #{instance.diameter}. It takes #{instance.day_length} to spin on its axis (that's one #{instance.name} day!) and it's atmosphere is composed of #{instance.atmosphere_contents}." | ||
| 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.
Good job re-working
Planet#initializeto take a hash.