forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 47
Branches - Clara #49
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
CEsGutierrez
wants to merge
5
commits into
Ada-C12:master
Choose a base branch
from
CEsGutierrez: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
Branches - Clara #49
Changes from all commits
Commits
Show all changes
5 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,87 @@ | ||
| require_relative 'planet' | ||
| require_relative 'solar_system' | ||
|
|
||
| def main # Creates solar system and populates it | ||
|
|
||
| # These loop options will be used later in the method to list for the user what they can do | ||
| loop_options = ["list planets", "planet details", "add planet", "exit"] | ||
|
|
||
| # Create and populate a solar system with 2 planets | ||
| solar_system_1 = SolarSystem.new("Red Dwarf") | ||
|
|
||
| planet_1 = Planet.new(name: "Din", color: "Pink", mass_kg: 237923789, distance_from_sun_km: 3278997897823575978987, fun_fact: "It's made out of cotton candy") | ||
|
|
||
| solar_system_1.add_planet(planet_1) | ||
|
|
||
| planet_2 = Planet.new(name: "Minnie", color: "orange", mass_kg: 780978, distance_from_sun_km: 9877984531234354, fun_fact: "It's made out of mustard") | ||
|
|
||
| solar_system_1.add_planet(planet_2) | ||
|
|
||
| # method that calls "find_planet_by_name" method from solar_system.rb | ||
| # placed here because it needs to access to previously entered information | ||
| def planet_details | ||
| print "Enter the name of the planet you want to search for: " | ||
| planet_search_term = gets.chomp.upcase | ||
| return_statement = find_planet_by_name(planet_search_term) | ||
| return return_statement | ||
| end | ||
|
|
||
| # method that manually enters planets into the previously established solar_system | ||
| # placed here because it needs to access to previously entered information | ||
| def add_planet_manually | ||
| print "What is the name of the planet you want to enter: " | ||
| name_manual = gets.chomp | ||
| print "What is its color? " | ||
| color_manual = gets.chomp | ||
| print "What is its mass: " | ||
| mass_manual = gets.chomp.to_i | ||
| print "What is its distance from the sun (km): " | ||
| distance_from_sun_km_manual = gets.chomp.to_i | ||
| print "What's a fun fact about this planet? " | ||
| fun_fact_manual = gets.chomp | ||
|
|
||
| user_planet = Planet.new(name: "#{name_manual}", color: "#{color_manual}", mass_kg: "#{mass_manual}", distance_from_sun_km: "#{distance_from_sun_km_manual}", fun_fact: "#{fun_fact_manual}") | ||
|
|
||
| return user_planet | ||
|
|
||
| end | ||
|
|
||
| # Asks user what to pursue next using the options from LN 6 | ||
| # Calls secondary methods depending on the user input | ||
| puts "What would you like to do next?" | ||
| loop_options.each do |option| | ||
| puts "\t #{option}" | ||
| end | ||
| eval = gets.chomp.downcase | ||
|
|
||
| # Creates a loop that traps the user until they enter "exit" | ||
| # The user can enter multiple planets manually | ||
| # The planets previously entered by the user are available in subsequent loops | ||
| until eval == "exit" do | ||
| case eval | ||
| when "list planets" | ||
| solar_system_1.list_planets.each do |line| | ||
| puts line | ||
| end | ||
| eval = nil | ||
| when "planet details" | ||
| puts solar_system_1.planet_details | ||
|
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. This is really stirring my curiosity. planet_details is not a method defined on the solar_system class so I'm not sure how this is working. |
||
| eval = nil | ||
| when "add planet" | ||
| solar_system_1.add_planet(add_planet_manually) | ||
| solar_system_1.list_planets.each do |line| | ||
| puts line | ||
| end | ||
| eval = nil | ||
| else | ||
| puts "What would you like to do next? " | ||
| loop_options.each do |option| | ||
| puts "\t #{option}" | ||
| end | ||
| eval = gets.chomp.downcase | ||
| end | ||
| end | ||
|
|
||
| end | ||
|
|
||
| main | ||
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,22 @@ | ||
| # creates a class | ||
| class Planet | ||
|
|
||
| # reader attributes | ||
| attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact | ||
|
|
||
| # constructor | ||
| # here the initial attributes are | ||
| def initialize(name:, color:, mass_kg:, distance_from_sun_km:, fun_fact:) | ||
| @name = name.upcase | ||
| @color = color.downcase | ||
| @mass_kg = mass_kg.to_i | ||
| @distance_from_sun_km = distance_from_sun_km.to_i | ||
| @fun_fact = fun_fact | ||
| end | ||
|
|
||
| # writes summary | ||
| def summary | ||
| return "Let's learn about #{@name.capitalize}. It is #{@color}, it has a mass of #{@mass_kg} kg, and it orbits #{@distance_from_sun_km} kilometers from the sun. Fun fact: #{@fun_fact}. \n" | ||
| 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,30 @@ | ||
| class SolarSystem | ||
|
|
||
| attr_reader :star_name, :planets | ||
|
|
||
| def initialize (star_name) | ||
| @star_name = star_name | ||
| @planets = [] | ||
| end | ||
|
|
||
| def add_planet (planet) | ||
| @planets.push planet | ||
| end | ||
|
|
||
| def list_planets | ||
| place = @planets.map.with_index do |planet, index| | ||
| "#{ index + 1 }. #{planet.name.capitalize}" | ||
| end | ||
| return place | ||
| end | ||
|
|
||
| def find_planet_by_name(planet_name) | ||
| planet_name.upcase | ||
| @planets.each do |planet| | ||
| if planet_name.upcase == planet.name.upcase | ||
| return planet.summary | ||
| end | ||
| end | ||
| 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,19 @@ | ||
| require 'minitest/autorun' | ||
| require 'minitest/reporters' | ||
| require 'minitest/skip_dsl' | ||
|
|
||
| require_relative '../main.rb' | ||
| require_relative '..planet.rb' | ||
|
|
||
| # Get that nice colorized output | ||
| Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new | ||
|
|
||
| describe 'planets' do | ||
| describe 'attributes entered' do | ||
| # checks that the name has at least 1 letter | ||
| # checks that the color has only letters | ||
| # checks that fun fact has an input | ||
| # checks that mass is not negative | ||
| # checks that the distance from the sun is not negative | ||
| 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.
This is really stirring my curiosity. find_planet_by_name is a method defined on the solar_system class so I'm not sure how this is working without calling it on an instance of solar_system.