Let's make a planetary system!
- Create a
Planetclass with a name attribute. You should be able to instantiate a newPlanetobject with an associated name.
- Give your
Planetclass 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.
- Give each planet a rate of solar rotation
- Give each planet a
@distance_from_the_sunattribute - Write a new program that asks for user input to query the planets using the
Planetclass 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.
- Create a
SolarSystemclass that has an attributeplanetsthat has zero to manyPlanetinstances. To create the Planet associations, yourSolarSystemshould:- 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
initializein thePlanetclass to accept a hash rather than individual parameters - Use a default value attribute in at least one method in your
Planetclass
- If you haven't already, add a
@distance_from_the_sunattribute to yourPlanet. Using this data, add a method to yourSolarSystemwhich 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