Skip to content
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

Sockets - Erica #24

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open

Sockets - Erica #24

wants to merge 18 commits into from

Conversation

norrise120
Copy link

Solar System

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
When does the initialize method run? What does it do? The 'initialize' method runs at the start of the instance of a new class. It creates instance variables of the parameters that are present in the constructor.
Why do you imagine we made our instance variables readable but not writable? We didn't make the variables writable, because we do not want the user changing the different attributes of the planets or solar system.
How would your program be different if each planet was stored as a Hash instead of an instance of a class? I feel like for the most part, the code would not be too different if we used a hash instead of a class for planets. However, in order to create something that is similar to the summary method, we would have to use much more complex code. (I do believe this could have been done though.)
How would your program be different if your SolarSystem class used a Hash instead of an Array to store the list of planets? The code would likely have been much, much more complex. Rather than having methods that I could easily call on the class, I would need to create several loops that would iterate through the array to get the planet I wanted and then write more code to work through the hashes to get the necessary pieces of information.
The Single Responsibility Principle (SRP) says that each class should be responsible for exactly one thing. Do your classes follow SRP? What responsibilities do they have? I believe my code follows SRP. The Planet class is in charge of the creating new instances of planets and giving a summary via the summary method. The Solar System is in charge of keeping track of all of the planets within the solar system and of performing different methods either on the solar system as a whole or between planets within the solar system.
How did you organize your require statements? Which files needed requires, and which did not? What is the pattern? I put the require statements at the tops of my files and included any files that directly referenced code in a different file. So my planet.rb did not have any require statements, solar_system.rb required planet.rb, and main.rb required solar_system.rb and planet.rb. Out of curiosity, I just checked to see if main.rb could require planet.rb through solar_system.rb (thus eliminating the need to require planet.rb in main.rb). I found that it could; however, I am choosing to leave it in for clarity as code from planet.rb is used in main.rb.

@droberts-sea
Copy link

Good job overall - this submission is well-organized and clearly hits the learning goals. Keep up the hard work!

solar_system = SolarSystem.new("Sol")
mercury = Planet.new("Mercury", "dark grey", 3.285e23, 5.791e7, "Named for the messenger of the Roman gods due to its orbital speed")
solar_system.add_planet(mercury)
venus = Planet.new("Venus", "red-brown", 4.867e24, 1.082e8, "Both the morning star and the evening star")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should wrap all this work in a main method.

def user_adds_planet
puts "Please complete the following information for the planet you would like added: \nName: "
name = gets.chomp.capitalize
puts "Color: "

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you've broken this out as a separate method. Since this method interacts with the user, it might fit better in main.rb, possibly taking the solar system as an argument.

def distance_between_by_input
puts "Please enter the two planets you would like to find the distance between:"
print "Planet 1: "
planet1 = self.find_planet_by_name(gets.chomp)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, it might make sense to split the user interaction pieces of this out into a separate method in main.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants