Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,29 @@ Let's make a planetary system!

# Wave 1
## Primary Requirements
- Get creative! Give each instance of `Planet` diameters, mass, moons.. whatever! __Allow these attributes to be set using a hash in initialize.__
- You should be able to create many different planets with different properties, like Mercury, Venus, Earth, Mars, Jupiter, etc.
- Give your `Planet` class some additional properties like diameter, mass, number of moons, and any other properties you think a planet should have.
- You should be able to create many different planet objects with different properties, like Mercury, Venus, Earth, Mars, Jupiter, etc.

## Optional Enhancements
- Give each planet a rate of solar rotation
- Give each planet a `@distance_from_the_sun` attribute

- Write a program that asks for user input to query the planets:
- Write a _new_ program that asks for user input to query the planets using the `Planet` class you have created:
- First, ask the user to select a planet they'd like to learn about.
- Present the user with a list of planets from which they can choose. Something like:
- `1. Mercury, 2. Venus, 3. Earth, 4. Secret Earth, 5. Mars, 6. Jupiter, ... 13. Exit`
- Provide the user with well formatted information about the planet (diameter, mass, number of moons, primary export, etc.)
- Then ask the user for another planet.


# Wave 2
## Primary Requirements
- Create a `SolarSystem` class that has an attribute `planets` that has zero to many `Planet` instances. There are a few different options for how to associate the planets with your solar system:
- Initialize the list of planets in the constructor of the solar system
- Create a method that adds a single planet to a solar system
- Create a method that adds a list of planets to the existing list of planets
- Create a `SolarSystem` class that has an attribute `planets` that has zero to many `Planet` instances. To create the Planet associations, your `SolarSystem` should:
- Have a method that adds a single planet to your solar system
- Have a second method that adds an array of planets to the existing array of planets
- Update your `initialize` in the `Planet` class to accept a hash rather than individual parameters
- Use a default value attribute in at least one method in your `Planet` class

## Optional Enhancements
- Ensure that the each planet has a `@distance_from_the_sun` attribute. Using this data, add a method to determine the distance from any other planet (assuming planets are in a straight line from the sun)
- If you haven't already, add a `@distance_from_the_sun` attribute to your `Planet`. Using this data, add a method to your `SolarSystem` which will calculate the distance between any two planets provided (assuming planets are in a straight line from the sun)
- Give your solar system a formation year (in earth years).
- Define a method that returns the local year of the planet based on it's rotation since the beginning of the solar system
70 changes: 70 additions & 0 deletions planet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class SolarSystem
attr_reader :planets

def intialize(planets)
planets.each do |planet|
@planets[planet.name] = planet
end
end

def add_planet(x)
@planets[x.name] = x
end

def remove_planet(planet_name)
@planets[planet_name] = nil
end

def name_of_planet(position)
planet_in_position = @planets[position]

planet_in_position.class #=> Planet
planet_in_position.colonized? #=> true or false
@planets[position].name
end

def distance_between(planet1, planet2)

end
end

class Planet
attr_reader :name, :earth_age

def initialize(options)
@name = options[:name]
@mass = options[:mass]
@rotation = options[:rotation]
@earth_age = options[:earth_age]
@distance = options[:distance]
@robots = options[:robots]
end

def colonized?
@robots == true
end
end


earth = Planet.new(name: "Earth", mass: 32598234, robots: true)
mars = Planet.new(name: "Earth", mass: 23455, robots: true)
solar_system = SolarSystem.new(name: "Our solar system", planets: [earth, mars])

venus = Planet.new(name: "Venus", mass: 2343284092384, robots: true)
planet_dog_food = Planet.new(name: "Dog Food", mass 0, robots: false)

solar_system.add_planet(venus)
solar_system.add_planet(planet_dog_food)



planets = {
"mercury" => Planet.new(),
"venus" => Planet.new()
}
choice = gets.chomp.downcase
planets[choice]