-
Notifications
You must be signed in to change notification settings - Fork 21
Add solar system wave 1 and wave 2 with planet and solar classes #4
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: cas/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,99 @@ | ||
| require "./planet_class" | ||
| require "./solar_class" | ||
|
|
||
| mercury_hash = { | ||
| name: "Mercury", | ||
| diameter: 3031, | ||
| distance_from_sun: 36, | ||
| number_of_moons: 0, | ||
| solar_rotation: 0.24 | ||
| } | ||
|
|
||
| venus_hash = { | ||
| name: "Venus", | ||
| diameter: 7521, | ||
| distance_from_sun: 67, | ||
| number_of_moons: 0, | ||
| solar_rotation: 0.62 | ||
| } | ||
|
|
||
| earth_hash = { | ||
| name: "Earth", | ||
| diameter: 7926, | ||
| distance_from_sun: 93, | ||
| number_of_moons: 1, | ||
| solar_rotation: 365.24 | ||
| } | ||
|
|
||
| mars_hash = { | ||
| name: "Mars", | ||
| diameter: 4217, | ||
| distance_from_sun: 93, | ||
| number_of_moons: 1, | ||
| solar_rotation: 697 | ||
| } | ||
|
|
||
| jupiter_hash = { | ||
| name: "Jupiter", | ||
| diameter: 88730, | ||
| distance_from_sun: 484, | ||
| number_of_moons: 16, | ||
| solar_rotation: 11.6 | ||
| } | ||
|
|
||
| saturn_hash = { | ||
| name: "Saturn", | ||
| diameter: 74900, | ||
| distance_from_sun: 888, | ||
| number_of_moons: 18, | ||
| solar_rotation: 29.5 | ||
| } | ||
|
|
||
| uranus_hash = { | ||
| name: "Uranus", | ||
| diameter: 31763, | ||
| distance_from_sun: 1780, | ||
| number_of_moons: 17, | ||
| solar_rotation: 84 | ||
| } | ||
|
|
||
| neptune_hash = { | ||
| name: "Neptune", | ||
| diameter: 31775, | ||
| distance_from_sun: 2800, | ||
| number_of_moons: 16, | ||
| solar_rotation: 165 | ||
| } | ||
|
|
||
| mercury = Planet.new(mercury_hash) | ||
| venus = Planet.new(venus_hash) | ||
| earth = Planet.new(earth_hash) | ||
| mars = Planet.new(mars_hash) | ||
| jupiter = Planet.new(jupiter_hash) | ||
| saturn = Planet.new(saturn_hash) | ||
| uranus = Planet.new(uranus_hash) | ||
| neptune = Planet.new(neptune_hash) | ||
|
|
||
|
|
||
| original_planets = [] | ||
| original_planets.push(mercury) | ||
| original_planets.push(venus) | ||
| original_planets.push(earth) | ||
| original_planets.push(mars) | ||
| original_planets.push(jupiter) | ||
| original_planets.push(saturn) | ||
| original_planets.push(uranus) | ||
| original_planets.push(neptune) | ||
|
|
||
| milky_way_hash = { | ||
| name: "Milky Way" | ||
| } | ||
|
|
||
| milky_way = Solar_System.new(milky_way_hash) | ||
|
|
||
| milky_way.add_many_planets(original_planets) | ||
|
|
||
| milky_way.print_planets | ||
|
|
||
|
|
||
| #milky_way.distance_away(mercury, neptune) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| class Planet | ||
| attr_accessor :name, :diameter, :distance_from_sun, :number_of_moons, :solar_rotation | ||
|
|
||
| def initialize(name, diameter, distance_from_sun, number_of_moons, solar_rotation) | ||
| @name = name | ||
| @diameter = diameter | ||
| @distance_from_sun = distance_from_sun | ||
| @number_of_moons = number_of_moons | ||
| @solar_rotation = solar_rotation | ||
| end | ||
|
|
||
| def print_out | ||
| puts "Let's talk about #{@name}." | ||
| puts "\n" | ||
| puts "#{@name} has a diameter of #{@diameter} and #{@number_of_moons} moons. It is #{@distance_from_sun} miles away from the sun, rotating around the sun for #{@solar_rotation} earth years in one rotation." | ||
| puts "\n\n\n" | ||
| end | ||
|
|
||
| end | ||
|
|
||
| mercury = Planet.new("Mercury", 3031, 36, 0, 0.24) | ||
| venus = Planet.new("Venus", 7521, 67, 0, 0.62) | ||
| earth = Planet.new("Earth", 7926, 93, 1, 365.24) | ||
| mars = Planet.new("Mars", 4217, 142, 2, 697) | ||
| jupiter = Planet.new("Jupiter", 88730, 484, 16, 11.9) | ||
| saturn = Planet.new("Saturn", 74900, 888, 18, 29.5) | ||
| uranus = Planet.new("Uranus", 31763, 1780, 17, 84) | ||
| neptune = Planet.new("Neptune", 31775, 2800, 16, 165) | ||
| pluto = Planet.new("Pluto", "n/a", "n/a", "n/a", "n/a") | ||
|
|
||
| nets = [] | ||
| nets.push(mercury, venus, earth, mars, jupiter, saturn, uranus, neptune) | ||
|
|
||
|
|
||
| def call_to_planets(planet_array) | ||
| puts "Hello! Check out the available planets to learn about:" | ||
| line_width = 60 | ||
| count = 1 | ||
| planet_array.each do |planet| | ||
| puts "#{count}. #{planet.name}".center(line_width) | ||
| count += 1 | ||
| end | ||
| puts "Which one interests you? Type the number or \"exit\" to quit:" | ||
| response = gets.chomp | ||
| return response | ||
| end | ||
|
|
||
| user_choice = call_to_planets(nets) | ||
|
|
||
|
|
||
| while user_choice.downcase != "exit" | ||
| puts "I can't do this off the top of my head. Let me consult my planet dictionary..." | ||
|
|
||
| nets[user_choice.to_i - 1].print_out | ||
|
|
||
| user_choice = call_to_planets(nets) | ||
| end | ||
|
|
||
| puts "Hope you learned something! Even if it was just that Pluto is not a planet. RIP" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| class Planet | ||
| attr_accessor :name, :diameter, :distance_from_sun, :number_of_moons, :solar_rotation, :badass | ||
|
|
||
| def initialize(planet_hash, badass = true) | ||
| @name = planet_hash[:name] | ||
| @diameter = planet_hash[:diameter] | ||
| @distance_from_sun = planet_hash[:distance_from_sun] | ||
| @number_of_moons = planet_hash[:number_of_moons] | ||
| @solar_rotation = planet_hash[:solar_rotation] | ||
| @badass = planet_hash[:badass] | ||
| end | ||
|
|
||
| def print_out | ||
| puts "Let's talk about #{@name}." | ||
| puts "\n" | ||
| puts "#{@name} has a diameter of #{@diameter} and #{@number_of_moons} moons. It is #{@distance_from_sun} miles away from the sun, rotating around the sun for #{@solar_rotation} earth years in one rotation." | ||
| if badass == false | ||
|
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. Watch your indentation here, you don't need to indent the |
||
| puts "Interestingly, this planet that is not badass at all. That is rare, and most likely due to its frigid temperatures, which make me sad." | ||
|
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. LOL! |
||
| end | ||
| puts "\n\n\n" | ||
| end | ||
|
|
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| class Solar_System | ||
| attr_accessor :planets, :name | ||
|
|
||
| def initialize(solar_hash) | ||
| @name = solar_hash[:name] | ||
| @planets = [] | ||
| end | ||
|
|
||
| def add_many_planets(planet_array) | ||
| planet_array.each do |plan| | ||
| @planets.push(plan) | ||
| puts plan.name | ||
| end | ||
| end | ||
|
|
||
| def add_one_planet(planet_hash) | ||
|
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. How does this one work? I don't see an example of you using this method |
||
| @planets.push(planet_hash) | ||
| end | ||
|
|
||
| def print_planets | ||
| @planets.length.times do |num| | ||
|
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. Nice use of the |
||
| puts "#{num + 1}. #{@planets[num].name}" | ||
| end | ||
| end | ||
|
|
||
| def distance_away(planet_a, planet_b) | ||
| distance =(planet_a.distance_from_sun - planet_b.distance_from_sun).abs | ||
| puts "The distance between #{planet_a.name} and #{planet_b.name} is #{distance} of some units I forget. Won't mean much anyway. On with your day." | ||
| end | ||
|
|
||
| end | ||
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.
Nice! I wonder if you could put all of the hashes into an array (maybe named hashes?) and then iterate over that array to add each of your planets: