Skip to content

Conversation

@brittanyrjones
Copy link

Solar System

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
What was the purpose of the initialize method in your class?
Describe an instance variable you used and what you used it for.
Describe what the difference would be if your SolarSystem used an Array vs a Hash.
Do you feel like you used consistent formatting throughout your code?

@CheezItMan
Copy link

Solar System

What We're Looking For

Feature Feedback
Baseline
Readable code with consistent indentation. No See my in-line notes.
Primary Requirements
Created Custom Solar System Class with initialize, add planet & list planets methods, without using puts. You have initialize and add_planet methods, but initialize is broken. The method to list planets also mixes roles (see my inline notes).
Planet Class Created Check
Created a collection of Planet objects as an instance variable in SolarSystem. You tried, but initialize is broken.
Accessor methods created Yes, but these should probably be attr_reader rather than attr_accessor.
Method created to return the Planet's attributes and not use puts Sort-f you have an accessor that returns a hash and the main program uses this. However by doing this there's little reason to use a class. Instead why not just use a hash.
Created a user interface to interact with the SolarSystem including adding a planet and viewing a planet's details The interface is created, but you're not using the numbers in the interface, so it's counterintuitive. You're also not using the SolarSystem class in the interface!
Additional Notes No answers to comprehension questions! This is a problematic submission. I know you had computer issues, but seeing how SolarSystem isn't used in the interface (and the fact that it's broken), is a bit worrying. For now focus on Word-Guess and try to put in place the concepts you had trouble with here, constructors, and separating roles in your classes. If you have questions lets sit down and look at things.

@@ -0,0 +1,97 @@
# Brittany Jones

Choose a reason for hiding this comment

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

This file should end with .rb


class Planet
# Create reader methods to give a user access to read the instance variables.
attr_accessor :planet_hash

Choose a reason for hiding this comment

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

Code inside a class should be indented. Either use 1 tab or 2 spaces to indent code.

Also why make this a hash or an accessor?

By being a hash a user of Planet must know the structure of the hash and they keys.

By using attr_accessor you are giving users the ability to change @planet_hash. You probably don't want to do that.

Granted in this project it's a minor issue.

#Create a SolarSystem class with an @planets instance variable.
#Make your SolarSystem class take an array of Planets instead of hashes. class will take an array of hashes, instead of hashes.
class SolarSystem
attr_accessor :planets

Choose a reason for hiding this comment

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

Similar issue with making this an acessor.

attr_accessor :planets
def initialize
@planets = planets
@planets = []

Choose a reason for hiding this comment

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

You are blanking out @planets so anything sent into initialize is erased.

Also your initialize method isn't getting sent a parameter.

You should have:

def initialize(planets)
  @planets = planets
end


def add_planet(planet)
@planets.push(planet)
end

Choose a reason for hiding this comment

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

weird indentation here with end

# Add planets to the @planets array.
def print
planets.each do |planet|
puts planet.name

Choose a reason for hiding this comment

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

You're doing what's called mixing roles here. Each class should focus on one role. SolarSystem should deal with storing planets and returning a list of planet names. Planet should store planet details and provide getter methods.

The main program's methods can deal with Input and output to the screen. That separation of roles can make things easier to reuse and modify.

planet_choice = gets.chomp.capitalize
puts "\n------------------------------------------------------------\n\n"

case planet_choice

Choose a reason for hiding this comment

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

You're not using the SolarSystem instance!

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