forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 48
Time - Lola #42
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
Open
ubeninja77
wants to merge
9
commits into
Ada-C13:master
Choose a base branch
from
ubeninja77:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Time - Lola #42
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
75c30d7
added empty file planet.rb
ubeninja77 783879c
wave 1 - solar system
ubeninja77 5f0bbc6
wave 1 - solar system
ubeninja77 96d8617
wave 1 - planet
ubeninja77 a226734
first part of wave 2 - made the solar_system class
ubeninja77 477c667
added user prompts for CLI
ubeninja77 9db1456
final planet.rb with updated summary
ubeninja77 5d4b388
updated solar_system.rb with find_planet def and list_planets def
ubeninja77 3b5f218
main.rb updated with CLI and adding planet
ubeninja77 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| require_relative "planet" | ||
| require_relative "solar_system" | ||
|
|
||
|
|
||
| def main | ||
| earth = Planet.new("Earth", "blue-green", 5.972e24,1.496e8, "Earth is the only planet in our solar system not to be named after a Roman or Green deity.") | ||
| mars = Planet.new("Mars", "red", 6.39e23, 227940000, "Olympus Mons, the tallest mountain in the solar system, calls Mars home.") | ||
| venus = Planet.new("Venus", "yellow", 4.867e24, 1.089e8, "Venus spins clockwise on its axis.") | ||
| mercury = Planet.new("Mercury", "yellow-blue", 3.285e23, 5.791e7, "Your weight on Mercury would be 38% of your weight on Earth.") | ||
| pluto = Planet.new("Pluto", "grey-orange", 1.30900e22, 5.906e9, "Named after the Roman god of the underworld.") | ||
|
|
||
|
|
||
| solar_system = SolarSystem.new("Sol") | ||
| solar_system.add_planet(earth) | ||
| solar_system.add_planet(mars) | ||
| solar_system.add_planet(venus) | ||
| solar_system.add_planet(mercury) | ||
| solar_system.add_planet(pluto) | ||
| list = solar_system.list_planets | ||
| puts list | ||
|
|
||
| until directions != "exit" | ||
| puts "Came to learn about planets, did yah? What would you like to do? Choose from list planets, planet details, add new planet, or exit." | ||
| user_choice = gets.chomp.downcase | ||
| if directions == "list planets" | ||
| user_choice = solar_system.list_planets | ||
| return list | ||
| elsif directions == "planet details" | ||
| puts "Which planet are you interested in?" | ||
| planet_selected = gets.chomp.downcase | ||
| return planet_details.summary | ||
| elsif directions == "add new planet" | ||
| solar_system.add_planet(planet_addition) | ||
| else | ||
| puts "That's all folks!" | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def add_planet(solar_system) | ||
| puts "What's the planet's name?" | ||
| name = gets.chomp | ||
| puts "What color is the planet?" | ||
| color = gets.chomp | ||
| puts "What is the planet's Mass in kg?" | ||
| mass_kg = gets.chomp | ||
| puts "What's the planet's distance from the sun in km?" | ||
| distance_from_sun_km = gets.chomp | ||
| puts "Share a fun fact about the planet!" | ||
| fun_fact = gets.chomp | ||
|
|
||
| new_planet = Planet.new(name, color, mass_kg, distance_from_sun_km, fun_fact) | ||
| return new_planet | ||
| # solar_system.add_planet(new_planet) | ||
| end | ||
|
|
||
| main | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,19 @@ | ||||||
| class Planet | ||||||
| attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact | ||||||
|
|
||||||
| def initalize(name, color, mass_kg, distance_from_sun_km, fun_fact) | ||||||
|
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. Initialize is misspelled
Suggested change
|
||||||
| @name = name.upcase | ||||||
| @color = color | ||||||
| @mass_kg = mass_kg | ||||||
| @distance_from_sun_km = distance_from_sun_km | ||||||
| @fun_fact = fun_fact | ||||||
| end | ||||||
|
|
||||||
| def summary | ||||||
| planet_details = | ||||||
| "The planet #{@name}'s is #{@color} in color and weighs #{@mass_kg} kgs. | ||||||
| #{@name}'s distance frome the sun is #{@distance_from_sun_km}. | ||||||
| Here's a fun nugget about #{@name}: #{@fun_fact}." | ||||||
| return planet_details | ||||||
| end | ||||||
| end | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| class SolarSystem | ||
| attr_reader :star_name, :planets | ||
|
|
||
| def initialize(star_name) | ||
| @star_name = star_name | ||
| @planets = [] | ||
| end | ||
|
|
||
| def add_planet(planet) | ||
| @planets << planet | ||
| end | ||
|
|
||
| def list_planets | ||
| planets_orbit = "Planets orbiting #{@star_name}." | ||
| @planets.each_with_index do |planet, index| | ||
| planets_orbit += "#{index + 1}: #{planet.name}" | ||
| end | ||
| return planets_orbit | ||
| end | ||
|
|
||
| def find_planet_by_name(name) | ||
| found = false | ||
| @planets.each do |planet| | ||
| if planet.name.downcase == name.downcase | ||
| found = true | ||
| return planet | ||
| else | ||
| found = false | ||
| end | ||
| end | ||
| if found == false | ||
| return "This is not a planet!" | ||
| end | ||
| end | ||
| end | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You should also initialize
directions, i.e. give it a start value.