forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 44
Mary Amper Solar System #41
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
mmlamkin
wants to merge
1
commit into
Ada-C9:master
Choose a base branch
from
mmlamkin: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
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,99 @@ | ||
| class SolarSystem | ||
|
|
||
| attr_accessor :planets | ||
|
|
||
| def initialize(planets) | ||
| @planets = planets | ||
| end | ||
|
|
||
| def list | ||
| name_list = [] | ||
| n = 0 | ||
| @planets.each do |planet| | ||
| name_list << "#{n + 1}. #{planet.name}" | ||
| n += 1 | ||
| end | ||
| return name_list | ||
| end | ||
|
|
||
| end | ||
|
|
||
|
|
||
| class Planet | ||
|
|
||
| attr_accessor :name, :moons, :year, :climate, :aliens, :age | ||
|
|
||
| def initialize(name, moons, year, climate, aliens, age) | ||
| @name = name | ||
| @moons = moons | ||
| @year = year | ||
| @climate = climate | ||
| @aliens = aliens | ||
| @age = age | ||
| end | ||
|
|
||
| def summary | ||
| return "#{@name}: | ||
| #{@name} has #{@moons} moons. | ||
| It takes #{@year} years to get around the sun | ||
| and has a #{@climate} climate. | ||
| Does it have aliens? #{@aliens} | ||
| #{@name} is #{@age} years old" | ||
| end | ||
|
|
||
| end | ||
|
|
||
| Mercury = Planet.new("Mercury", 3, 0.7, "hot", "yes", 8088 ) | ||
| Venus = Planet.new("Venus", 7, 3, "cold", "no", 10009 ) | ||
| Earth = Planet.new("Earth", 4, 1, "warm", "yes", 2993884 ) | ||
| Mars = Planet.new("Mars", 3, 5, "dry", "no", 987323 ) | ||
| Jupiter = Planet.new("Jupiter", 2, 4, "gassy", "yes", 208345 ) | ||
| Hoth = Planet.new("Hoth", 0, 80, "deadly", "yes", 38775203 ) | ||
|
|
||
| planet_list = [ Mercury, Venus, Earth, Mars, Jupiter, Hoth ] | ||
| user_planet_list = [ "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Hoth" ] | ||
|
|
||
| Milky_Way = SolarSystem.new(planet_list) | ||
|
|
||
|
|
||
| puts "\n---Welcome to Mary's 100% REAL encyclopedia of the Milky Way---" | ||
|
|
||
| loop do | ||
|
|
||
| puts "\n\nCheck out the planets you can learn about! | ||
| Type the planet name or 'new' if you're a genius and discovered a new one!\n" | ||
|
|
||
| puts Milky_Way.list | ||
|
|
||
| user_choice = gets.chomp.capitalize | ||
|
|
||
| until user_choice == "New" || user_planet_list.include?(user_choice) | ||
| puts "Please pick a planet or type new" | ||
| user_choice = gets.chomp.capitalize | ||
| end | ||
|
|
||
| if user_choice == "New" | ||
| print "Great, what's your new planet's name? " | ||
| user_name = gets.chomp.capitalize | ||
| print "How many moons does it have? " | ||
| user_moon = gets.chomp.to_i | ||
| print "How long is it's year (in Earth years)? " | ||
| user_year = gets.chomp.to_f | ||
| print "What is the climate like? " | ||
| user_climate = gets.chomp | ||
| print "Does it have aliens? " | ||
| user_aliens = gets.chomp | ||
| print "How old is #{user_name}? " | ||
| user_age = gets.chomp.to_i | ||
| user_choice = Planet.new("#{user_name}", "#{user_moon}", "#{user_year}", "#{user_climate}", "#{user_aliens}", "#{user_age}") | ||
| user_planet_list << user_name | ||
| planet_list << user_choice | ||
| elsif user_planet_list.include?(user_choice) | ||
| planet_list.each do |planet| | ||
| if user_choice == planet.name | ||
| puts "#{planet.summary}" | ||
| end | ||
| end | ||
| 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.
It would be great if on this line and line 90 you used
Milky_Way.planetsinstead ofplanet_list!Better yet, maybe you can make an
add_planetmethod on SolarSystem, so line 90 instead reads: