-
Notifications
You must be signed in to change notification settings - Fork 44
Kiera Thomasson - Octos - Solar System #37
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| # wave 2 | ||
| class SolarSystem | ||
| attr_accessor :planet_list | ||
| # #initialize the method | ||
| def initialize(planet_list) | ||
| @planet_list = planet_list | ||
| end | ||
|
|
||
| # add new planet to list | ||
| def add_planet(name, position, color, attr_a, attr_b) | ||
| return @planet_list << planet_list | ||
| 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. This method should take one argument, an instance of |
||
|
|
||
| def list | ||
| summary = "" | ||
| i = 1 | ||
| @planet_list.each do |planet| | ||
| summary += "#{i}.#{planet.name}\n" | ||
| i += 1 | ||
| end | ||
| return summary | ||
| end | ||
|
|
||
| def summary_sol | ||
| return "The planets name is #{@name}. It is in the #{@position} position in the solar system. It is #{@color}. It has two random attributes that are #{@attr_a} and #{@attr_b}." | ||
| 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. I don't know if this method makes sense in the context of |
||
|
|
||
| def list_summary | ||
| summary = "" | ||
| i = 1 | ||
| @planet_list.each do |planet| | ||
| summary += "#{i}.#{planet.summary_sol}\n\n" | ||
|
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. Line 32 gave me an error. Looks like the |
||
| i += 1 | ||
| end | ||
| return summary | ||
| end | ||
| end | ||
|
|
||
| # create a planet class which will represent a planet | ||
| class Planet | ||
| # create a reader methods to give a user access to | ||
| #read the instance variables | ||
| attr_accessor :name, :position, :color, :attr_a, :attr_b | ||
| # add an initialize method that will take in multiple arguments | ||
| def initialize(name, position, color, attr_a, attr_b) | ||
| @name = name | ||
|
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. I like that you took our placeholder attributes and ran with them! |
||
| @position = position | ||
| @color = color | ||
| @attr_a = attr_a | ||
| @attr_b = attr_b | ||
| end | ||
| # create a method that will return the planets attributes in an | ||
| # easy to read fashion | ||
| def summary_user | ||
| return "The planet you chose was #{@name}. It is in the #{@position} position in the solar system. It is #{@color}. It has two random attributes that are #{@attr_a} and #{@attr_b}." | ||
| end | ||
|
|
||
| end | ||
|
|
||
|
|
||
|
|
||
| # make your SolarSystem class take an array of planets instead | ||
| # it should call corresponding method in Planet | ||
| planet_a = Planet.new("Mercury", "first", "gold", "love","hate") | ||
| planet_b = Planet.new("Venus", "second", "purple", "high", "low") | ||
| planet_c = Planet.new("Earth", "third", "green", "life", "death") | ||
| planet_d = Planet.new("Mars", "fourth", "red", "blah", "bleee") | ||
| planet_e = Planet.new("Jupiter", "fifth", "blue", "middle", "last") | ||
|
|
||
| planet_list = [planet_a, planet_b, planet_c, planet_d, planet_e] | ||
|
|
||
|
|
||
| my_solarsystem = SolarSystem.new(planet_list) | ||
| puts my_solarsystem.list | ||
|
|
||
| puts "\n\n" | ||
|
|
||
| # Create an interface where the user can interact with the solar system and be able to select a planet and view information about it. | ||
|
|
||
| # welcome user to program | ||
| puts "Welcome to Kiera's weird Solar System!!!!" | ||
| puts "In this solar sytem you can choose a planet, learn information about it as well as add your own planets.\n\n" | ||
| puts "--------------Lets get started--------------\n\n" | ||
|
|
||
| # ask user what planet they would like information on | ||
| # Allow your user to add their own planet. | ||
| puts "There are 2 options of play with the Weird Solar System\n\n" | ||
| puts "Please choose an option number to continue" | ||
| puts "Option 1. Learn about a planet ---- OR ---- Option 2. Add a planet to the Solar System\n" | ||
| play_option = gets.chomp | ||
|
|
||
| puts "\n\n" | ||
|
|
||
|
|
||
|
|
||
| new_planet =[] | ||
| if play_option == "1" | ||
| puts "Choose a planet you would like information on.\n" | ||
| puts my_solarsystem.list | ||
| puts "\n\n" | ||
| user_option = gets.chomp | ||
| puts "\n\n" | ||
| case user_option | ||
| when "mercury", "1" | ||
| puts planet_a.summary_user | ||
| when "venus", "2" | ||
| puts planet_b.summary_user | ||
| when "earth", "3" | ||
| puts planet_c.summary_user | ||
| when "mars", "4" | ||
| puts planet_d.summary_user | ||
| when "jupiter", "5" | ||
| puts planet_e.summary_user | ||
| else | ||
| print "SORRY, That planet is not included in the list" | ||
| end | ||
| elsif play_option == "2" | ||
| puts "Choose a planet name" | ||
| new_planet_name= gets.chomp | ||
| new_planet << new_planet_name | ||
| puts "Choose a planet position (number cannot be 1-5)" | ||
| new_planet_position = gets.chomp | ||
| new_planet << new_planet_position | ||
|
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. You're shoveling these variables into an array - I'm not sure that's what you want. Instead, you should use them as the arguments to call puts "Choose a planet name"
new_planet_name = gets.chomp
puts "Choose a planet position..."
new_planet_position = gets.chomp
# ... rest of the attributes
new_planet = Planet.new(new_planet_name, new_planet_position, ...)
my_solar_system.add_planet(new_planet) |
||
| puts "Choose a planet color" | ||
| new_planet_color = gets.chomp | ||
| new_planet << new_planet_color | ||
| puts "Choose an attribute" | ||
| new_planet_attr_a = gets.chomp | ||
| new_planet << new_planet_attr_a | ||
| puts "Choose another attribute" | ||
| new_planet_attr_b = gets.chomp | ||
| new_planet << new_planet_attr_b | ||
| else | ||
| puts "Sorry that is an incorrect option." | ||
| end | ||
|
|
||
| planet_g = Planet.new("new_planet_name", "new_planet_postiion", "new_planet_color", "new_planet_attr_a", "new_planet_attr_b") | ||
|
|
||
| print planet_g | ||
|
|
||
| planet_list << planet_g | ||
|
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. In stead of referencing the |
||
| puts my_solarsystem.list_summary | ||
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.
Files in Ruby should be named using snake_case. So this one would be
solar_system.rb(little 's').The decision is a little arbitrary, but especially once we start working on group projects it will be important to make sure everyone is doing the same thing.