forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 44
Octos - Hannah Cameron - Solar System #42
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
hannahlcameron
wants to merge
1
commit into
Ada-C9:master
Choose a base branch
from
hannahlcameron: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,111 @@ | ||
| # class for solarsystem that can contain mulitple planets | ||
| class SolarSystem | ||
|
|
||
| attr_accessor :planets | ||
|
|
||
| def initialize(planet_names) | ||
| @planets = planet_names | ||
| end | ||
|
|
||
| def add_planet(new_planet) | ||
| @planets << new_planet | ||
| end | ||
|
|
||
| def planets_listed | ||
| n = 1 | ||
| listed_planets = "" | ||
| @planets.each do |planet| | ||
| listed_planets += "#{n}.\t #{planet.name}\n" | ||
| n += 1 | ||
| end | ||
| return listed_planets | ||
| end | ||
|
|
||
| def return_specific_planet(planet_num) | ||
| return @planets[planet_num -1] | ||
| end | ||
| end | ||
|
|
||
| # class for planet that sets up a new planet | ||
| class Planet | ||
| attr_reader :name, :terraform_state, :temperature, :atmosphere, :location | ||
|
|
||
| def initialize(name, terraform_state, temperature, atmosphere, location) | ||
| @name = name | ||
| @terraform_state = terraform_state | ||
| @temperature = temperature | ||
| @atmosphere = atmosphere | ||
| @location = location | ||
| end | ||
|
|
||
| # Array style of returning planet info | ||
| def return_planet | ||
| terrraform_info = "" | ||
| if @terraform_state | ||
| terrraform_info = "Additionally, it has been terraformed." | ||
| else | ||
| terrraform_info = "Additionally, it has not been terraformed." | ||
| end | ||
| planet_info = "#{@name} is a planet located in the #{@location} galaxy. It is a #{@temperature} planet, whose atmosphere is #{@atmosphere} to humans. #{terrraform_info}" | ||
| return planet_info | ||
| end | ||
| end | ||
| # Hard coded data that pre-populates solar system | ||
|
|
||
| venus = Planet.new("Venus", false, "hot", "unbreathable", "Milky Way") | ||
|
|
||
| jupiter = Planet.new("Mercury", false, "hot", "unbreathable", "Milk Way") | ||
|
|
||
| pluto = Planet.new("Pluto", false, "hot", "unbreathable", "Milky Way") | ||
|
|
||
| planet_list = [ | ||
| venus, | ||
| jupiter, | ||
| pluto | ||
| ] | ||
|
|
||
| # initializes solar system | ||
| my_solar_system = SolarSystem.new(planet_list) | ||
|
|
||
| puts "Welcome to the Solar System 2000, where you can learn information about the planets in the database or you can add in your own planets!" | ||
|
|
||
| puts "What would you like to do? If you want to examine the planets that already are in the system, type 'See Planets'. If you want to add a planet, type 'Add Planet'. If at any point you wish to quit the program, type 'exit'." | ||
|
|
||
| user_decision = gets.chomp.upcase | ||
|
|
||
| until user_decision == "SEE PLANETS" || user_decision == "ADD PLANET" | ||
| puts "Oops! That's not one of the options I can perform. Please enter 'See Planets' or 'Add Planet'. If at any point you wish to quit the program, type 'exit'." | ||
| user_decision = gets.chomp.upcase | ||
| end | ||
|
|
||
| if user_decision == "SEE PLANETS" | ||
| puts "Here's a list of the planets in our solar system.\n#{my_solar_system.planets_listed}\n Please type the number of the planet you would like to learn about:" | ||
| planet_selection_num = gets.chomp.to_i | ||
| # Assuming reliable input that matches a listed planet #, will update to validate user input time permitting | ||
| puts my_solar_system.return_specific_planet(planet_selection_num).return_planet | ||
| else | ||
| puts "In order to create a new planet, you'll need to enter in some information. What is the planet's name?" | ||
| new_planet_name = gets.chomp | ||
| puts "Has this planet been terraformed? Please enter true or false:" | ||
| new_planet_terraform_state = gets.chomp | ||
| # Assuming reliable input of either "true" or "false", will update to validate user input time permitting | ||
| if new_planet_terraform_state == "true" | ||
| new_planet_terraform_state = true | ||
| else | ||
| new_planet_terraform_state = false | ||
| end | ||
| puts "Does the planet have a cold, temperate or hot temperature?" | ||
| new_planet_temperature = gets.chomp | ||
| # Assuming reliable input of either "cold", "temperate" or "hot", will update to validate user input time permitting | ||
| puts "Is the atmosphere breathable or unbreathable?" | ||
| new_planet_atmosphere = gets.chomp | ||
| # Assuming reliable input of either "breathable" or "unbreathable", will update to validate user input time permitting | ||
| puts "Which galaxy is the planet located in?" | ||
| new_planet_location = gets.chomp | ||
|
|
||
| new_planet_name = Planet.new("#{new_planet_name}", new_planet_terraform_state, "#{new_planet_temperature}", "#{new_planet_atmosphere}", "#{new_planet_location}") | ||
|
|
||
| my_solar_system.add_planet(Planet.new("#{new_planet_name}", new_planet_terraform_state, "#{new_planet_temperature}", "#{new_planet_atmosphere}", "#{new_planet_location}")) | ||
|
|
||
| puts "You just added #{new_planet_name} as a planet, which located in the #{new_planet_location} galaxy. It is a #{new_planet_temperature} planet, whose atmosphere is #{new_planet_atmosphere} to humans." | ||
|
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.
|
||
| 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 good to put this in some kind of loop that would let us to look at a number of planets.