forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 44
Ampers Week1 Sara S Solar System #36
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
CheerOnMars
wants to merge
6
commits into
Ada-C9:master
Choose a base branch
from
CheerOnMars: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
6 commits
Select commit
Hold shift + click to select a range
072c9b4
Create solar_system_wave1.rb
CheerOnMars 77bbb5d
Create solar_system_wave2.rb
CheerOnMars e5a4976
Update solar_system_wave2.rb
CheerOnMars ff31605
Create solar_system_wave1b.rb
CheerOnMars dcb9fed
Update solar_system_wave2.rb
CheerOnMars a5dbe7c
Create solar_system_wave3.rb
CheerOnMars 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,51 @@ | ||
| # Create a SolarSystem class with an @planets instance variable. | ||
| # Create an initialize method which should take a collection of planet names and store them in an @planets instance variable. | ||
| # Create a method that adds a planet to the list (not using user input). | ||
| # Create a method which will return, not print, a list of the planets as a String. | ||
| # Write code to test your SolarSystem | ||
| # Modify SolarSystem's initialize method to take a list of hashes where each planet is sent as a hash with at least 5 attributes. | ||
|
|
||
| # Define the class | ||
| class SolarSystem | ||
|
|
||
| # reader for planet | ||
| def planets | ||
| return @planets | ||
| end | ||
|
|
||
| # writer for planet | ||
| def planets=(new_planet) | ||
| @planets = new_planet | ||
| end | ||
|
|
||
| attr_accessor :order | ||
|
|
||
| # initialize method | ||
| def initialize(planets) | ||
| @planets = planets | ||
| end | ||
|
|
||
| def self.planets | ||
| return @planets | ||
| end | ||
|
|
||
| @planets = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"] | ||
|
|
||
| end | ||
|
|
||
| # code to test | ||
| SolarSystem.planets.each_with_index do |planet, i| | ||
| puts "#{i+1}. #{planet}" | ||
| end | ||
|
|
||
|
|
||
|
|
||
| mercury = { planets: "MercuryA", radius: 1516, moons: 0, rotation_period: 58.646, orbit_period: 0.2408467, rings: "No" } | ||
| venus = { planets: "VenusA", radius: 3760, moons: 0, rotation_period: -243.018, orbit_period: 0.61519726, rings: "No"} | ||
| earth = { planets: "EarthA", radius: 6371, moons: 1, rotation_period: 0.99726968, orbit_period: 1.0000174, rings: "No" } | ||
| mars = { planets: "MarsA", radius: 3389, moons: 2, rotation_period: 1.026, orbit_period: 1.8808476, rings: "No" } | ||
| jupiter = { planets: "JupiterA", radius: 69911 , moons: 69, rotation_period: 0.41354, orbit_period: 11.862615, rings: "Yes" } | ||
| saturn = { planets: "SaturnA", radius: 58232, moons: 62, rotation_period: 0.444, orbit_period: 29.447498, rings: "Yes" } | ||
| uranus = { planets: "UranusA", radius: 25362 , moons: 27, rotation_period: -0.718, orbit_period: 84.016846, rings: "Yes" } | ||
| neptune = { planets: "NeptuneA", radius: 24622 , moons: 14, rotation_period: 0.671, orbit_period: 164.79132, rings: "Yes" } | ||
|
|
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,134 @@ | ||
| # Create a SolarSystem class with an @planets instance variable. | ||
| # Create an initialize method which should take a collection of planet names and store them in an @planets instance variable. | ||
| # Create a method that adds a planet to the list (not using user input). | ||
| # Create a method which will return, not print, a list of the planets as a String. | ||
| # Write code to test your SolarSystem | ||
| # Modify SolarSystem's initialize method to take a list of hashes where each planet is sent as a hash with at least 5 attributes. | ||
|
|
||
| # Define the class | ||
| class SolarSystem | ||
|
|
||
| # reader for planet | ||
| def planets | ||
| return @planets | ||
| end | ||
|
|
||
| # writer for planet | ||
| def planets=(new_planet) | ||
| @planets = new_planet | ||
| end | ||
|
|
||
| #attr_accessor :order, | ||
| attr_accessor :radius | ||
| attr_accessor :moons | ||
| attr_accessor :rotation_period | ||
| attr_accessor :orbit_period | ||
| attr_accessor :rings | ||
|
|
||
|
|
||
| # initialize method | ||
| def initialize(planets_hash) | ||
| @planets = planets_hash[:planets] | ||
| @radius = planets_hash[:radius] | ||
| @moons = planets_hash[:moons] | ||
| @rotation_period = planets_hash[:rotation_period] | ||
| @orbit_period = planets_hash[:orbit_period] | ||
| @rings = planets_hash[:rings] | ||
| end | ||
|
|
||
| def self.planets | ||
| return @planets | ||
| end | ||
|
|
||
| #@planets = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"] | ||
|
|
||
| end | ||
|
|
||
| puts | ||
| mercury = SolarSystem.new ({ | ||
| planets: "MercuryA", | ||
| radius: 1516, | ||
| moons: 0, | ||
| rotation_period: 58.646, | ||
| orbit_period: 0.2408467, | ||
| rings: "No" | ||
| }) | ||
|
|
||
|
|
||
| venus = SolarSystem.new ({ | ||
| planets: "VenusA", | ||
| radius: 3760, | ||
| moons: 0, | ||
| rotation_period: -243.018, | ||
| orbit_period: 0.61519726, | ||
| rings: "No" | ||
| }) | ||
|
|
||
|
|
||
| earth = SolarSystem.new ({ | ||
| planets: "EarthA", | ||
| radius: 6371, | ||
| moons: 1, | ||
| rotation_period: 0.99726968, | ||
| orbit_period: 1.0000174, | ||
| rings: "No" | ||
| }) | ||
|
|
||
| mars = SolarSystem.new ({ | ||
| planets: "MarsA", | ||
| radius: 3389, | ||
| moons: 2, | ||
| rotation_period: 1.026, | ||
| orbit_period: 1.8808476, | ||
| rings: "No" | ||
| }) | ||
|
|
||
| jupiter = SolarSystem.new ({ | ||
| planets: "JupiterA", | ||
| radius: 69911 , | ||
| moons: 69, | ||
| rotation_period: 0.41354, | ||
| orbit_period: 11.862615, | ||
| rings: "Yes" | ||
| }) | ||
|
|
||
| saturn = SolarSystem.new ({ | ||
| planets: "SaturnA", | ||
| radius: 58232, | ||
| moons: 62, | ||
| rotation_period: 0.444, | ||
| orbit_period: 29.447498, | ||
| rings: "Yes" | ||
| }) | ||
| uranus = SolarSystem.new ({ | ||
| planets: "UranusA", | ||
| radius: 25362 , | ||
| moons: 27, | ||
| rotation_period: -0.718, | ||
| orbit_period: 84.016846, | ||
| rings: "Yes" | ||
| }) | ||
| neptune = SolarSystem.new ({ | ||
| planets: "NeptuneA", | ||
| radius: 24622 , | ||
| moons: 14, | ||
| rotation_period: 0.671, | ||
| orbit_period: 164.79132, | ||
| rings: "Yes" }) | ||
|
|
||
| puts mercury.planets | ||
| puts | ||
| puts venus.planets | ||
| puts | ||
| puts earth.planets | ||
| puts | ||
| puts mars.planets | ||
| puts | ||
| puts jupiter.planets | ||
| puts | ||
| puts saturn.planets | ||
| puts | ||
| puts uranus.planets | ||
| puts | ||
| puts neptune.planets | ||
| puts |
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,76 @@ | ||
| # Create a SolarSystem class with an @planets instance variable. | ||
| # Create an initialize method which should take a collection of planet names and store them in an @planets instance variable. | ||
| # Create a method that adds a planet to the list (not using user input). | ||
| # Create a method which will return, not print, a list of the planets as a String. | ||
| # Write code to test your SolarSystem | ||
| # Modify SolarSystem's initialize method to take a list of hashes where each planet is sent as a hash with at least 5 attributes. | ||
|
|
||
| # Define the class | ||
| class SolarSystem | ||
|
|
||
| def initialize(planets) | ||
| @planets = planets | ||
| end | ||
|
|
||
| attr_reader :planets | ||
|
|
||
| def puts_self | ||
| puts self | ||
| end | ||
|
|
||
| def self.planets | ||
| return @planets | ||
| end | ||
|
|
||
| def planet | ||
| puts | ||
| end | ||
| arr_planets = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"] | ||
|
|
||
| @planets = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"] | ||
|
|
||
| end | ||
|
|
||
| class Planet | ||
|
|
||
| attr_accessor :name | ||
| attr_accessor :order | ||
| attr_accessor :radius | ||
| attr_accessor :moons | ||
|
|
||
| def initialize(name, order, radius, moons) | ||
| @name = name | ||
| @order = order | ||
| @radius = radius | ||
| @moons = moons | ||
| end | ||
|
|
||
| def puts_self | ||
| puts self | ||
| end | ||
|
|
||
| def self.name | ||
| return @name | ||
| end | ||
|
|
||
| # instance method | ||
| def summary | ||
| return " #{order}. #{name} - Radius: #{radius}km. Number of Moons: #{moons}." | ||
| end | ||
|
|
||
| def self.summary | ||
| return @summary | ||
| end | ||
|
|
||
| end | ||
|
|
||
| planet_arr = [ | ||
| Planet.new("Mercury", 1, 2440 , 0), | ||
| Planet.new("Venus", 2, 6052 , 0), | ||
| Planet.new("Earth", 3, 6371 ,1) | ||
| ] | ||
|
|
||
| puts | ||
| planet_arr.each do |i| | ||
| puts i.summary | ||
| 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,109 @@ | ||
| class SolarSystem | ||
|
|
||
| def initialize(planets) | ||
| @planets = planets | ||
| end | ||
|
|
||
| attr_reader :planets | ||
|
|
||
| def puts_self | ||
| puts self | ||
| end | ||
|
|
||
| def self.planets | ||
| return @planets | ||
| end | ||
| end | ||
|
|
||
| class Planet | ||
|
|
||
| attr_accessor :name, :order, :radius, :moons | ||
|
|
||
| def initialize(name, order, radius, moons) | ||
| @name = name | ||
| @order = order | ||
| @radius = radius | ||
| @moons = moons | ||
| end | ||
|
|
||
| def puts_self | ||
| puts self | ||
| end | ||
|
|
||
| def self.name | ||
| return @name | ||
| end | ||
|
|
||
| # instance method | ||
| def contents | ||
| return " #{order}. #{name}" | ||
| end | ||
|
|
||
| def self.contents | ||
| return @contents | ||
| end | ||
|
|
||
| def summary | ||
| return " #{name} - Radius: #{radius}km. Number of Moons: #{moons}." | ||
| end | ||
|
|
||
| def self.summary | ||
| return @summary | ||
| end | ||
|
|
||
| end | ||
|
|
||
| # input planets | ||
| planet_arr = [ | ||
| Planet.new("Mercury", 1, 2440, 0), | ||
| Planet.new("Venus", 2, 6052, 0), | ||
| Planet.new("Earth", 3, 6371, 1), | ||
| Planet.new("Mars", 4, 3390, 2), | ||
| Planet.new("Jupiter", 5, 69911, 2), | ||
| Planet.new("Saturn", 6, 58232, 2), | ||
| Planet.new("Uranus", 7, 25362, 2), | ||
| Planet.new("Neptune", 8, 24622, 2), | ||
| ] | ||
|
|
||
| #outputs planets | ||
| puts | ||
| print "Welcome to this Solar System directory! Here is a list of planets: " | ||
| puts | ||
| planet_arr.each_with_index do |planet, i| | ||
| puts "#{i+1}. #{planet.name}" | ||
| end | ||
|
|
||
| puts | ||
| print "Type LEARN to learn about a planet. Type NEW to add a new planet: " | ||
| selection = gets.chomp.upcase! | ||
| if selection == "LEARN" | ||
| print "Please type the number of the planet you'd like to learn about: " | ||
| learn_option = gets.chomp.to_i | ||
| counter = 0 | ||
| until learn_option >= 0 && learn_option <= planet_arr.length | ||
| counter += 1 | ||
| if counter == 3 | ||
| puts "Too many incorrect attempts. Goodbye" | ||
| exit | ||
| else | ||
| print "You did not type a valid number. Please try again: " | ||
| learn_option = gets.chomp.to_i | ||
| end | ||
| end | ||
| puts planet_arr[learn_option-1].summary | ||
| elsif selection == "NEW" | ||
| print "What's the planet name? " | ||
| input_name = gets.chomp.upcase! | ||
| print "What's the radius of #{input_name} in kilometers? " | ||
| input_radius = gets.chomp.to_i | ||
| print "How many moons does #{input_name} have? " | ||
| input_moons = gets.chomp.to_i | ||
| planet_arr << Planet.new(input_name, 0, input_radius, input_moons) | ||
| puts "Here's an updated list of planets: " | ||
| planet_arr.each_with_index do |planet, i| | ||
| puts "#{i+1}. #{planet.summary} " | ||
| else | ||
| puts "You did not enter a valid option. Goodbye" | ||
| end | ||
|
|
||
| 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. the code starting at line 103 through the end of the file should read instead: planet_arr.each_with_index do |planet, i|
puts "#{i+1}. #{planet.summary} "
end
else
puts "You did not enter a valid option. Goodbye"
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.
starting at line 81, you have a small bug!
when
gets.chomp.to_iexecutes on line 81, if I type in a non-integer (like "asdlfkjasdf"), then the value oflearn_optionwill default to0.Because
learn_optionis 0, it will skip over theuntilblock on line 83, and then jump straight to line 93. iflearn_optionis 0, thenplanet_arr[0-1]will meanplanet_arr[-1], which will always choose the last element in the array.