forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Leaves_Ga-Young #35
Open
gyjin
wants to merge
7
commits into
Ada-C12:master
Choose a base branch
from
gyjin: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
Leaves_Ga-Young #35
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
97226b5
Completed wave-1, add main method
gyjin 9830275
Completed wave-1, added Planet class and summary
gyjin 371df71
Complete wave-2, added planet list and find planet
gyjin 8f611fa
Complete wave-2, create solar system class/methods
gyjin 6d5845a
Completed wave-3, added user interaction
gyjin 2d37b09
Added comments
gyjin ba5f421
Added error handling in user interaction
gyjin 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 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,44 @@ | ||
# Ga-Young Jin, Cohort 12 | ||
# Monday, August 19th, 2019 | ||
# Week 3, Solar System Project | ||
|
||
require_relative 'planet' | ||
require_relative 'solar_system' | ||
|
||
def main | ||
# initiating new solar system and planets | ||
solar_system = SolarSystem.new('Sol') | ||
earth = Planet.new('Earth', 'blue-green', 5.972e24, 1.496e8, 'Only planet known to support life') | ||
mars = Planet.new('Mars', 'red', 6.39e23, 2.28e8, 'The planet is named after Mars, the Roman god of war') | ||
|
||
solar_system.add_planet(earth) | ||
solar_system.add_planet(mars) | ||
|
||
# user interaction to explore and search through planets | ||
do_next = nil | ||
until do_next == "EXIT" || do_next == "4" | ||
puts "\nWhat would you like to do? | ||
1. List planets | ||
2. Get planet details | ||
3. Add planet | ||
4. Exit\n" | ||
|
||
do_next = gets.chomp | ||
|
||
case do_next | ||
when "LIST PLANETS", "1" | ||
puts solar_system.list_planets | ||
when "GET PLANET DETAILS", "2" | ||
puts solar_system.planet_details | ||
when "ADD PLANET", "3" | ||
solar_system.add_new_planet | ||
when "EXIT", "4" | ||
else | ||
puts "\nYou have entered an invalid response. Please try again." | ||
end | ||
end | ||
end | ||
|
||
main | ||
|
||
|
This file contains 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,21 @@ | ||
# Ga-Young Jin, Cohort 12 | ||
# Monday, August 19th, 2019 | ||
# Week 3, Solar System Project | ||
|
||
class Planet | ||
attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact | ||
|
||
def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact) | ||
@name = name | ||
@color = color | ||
@mass_kg = mass_kg | ||
@distance_from_sun_km = distance_from_sun_km | ||
@fun_fact = fun_fact | ||
end | ||
|
||
# method that returns a nice summary of a planet | ||
def summary | ||
return "\nThis planet is called #{@name}. It is #{@color} in color, #{@mass_kg} kilograms in weight, | ||
and #{@distance_from_sun_km} kilometers from the sun. A fun fact about this planet: #{@fun_fact}." | ||
end | ||
end |
This file contains 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,78 @@ | ||
# Ga-Young Jin, Cohort 12 | ||
# Monday, August 19th, 2019 | ||
# Week 3, Solar System Project | ||
|
||
class SolarSystem | ||
def initialize(star_name) | ||
@star_name = star_name | ||
@planets = [] | ||
end | ||
|
||
attr_reader :star_name, :planets | ||
|
||
# method to add a new planet to the planet array | ||
def add_planet(planet) | ||
@planets << planet | ||
end | ||
|
||
# method to list all planets in the planet array | ||
def list_planets | ||
planet_count = 1 | ||
list = "\nPlanets orbiting #{star_name} \n" | ||
@planets.each do |planet| | ||
list = list + "#{planet_count}. #{planet.name} \n" | ||
planet_count += 1 | ||
end | ||
return list | ||
end | ||
|
||
# method that asks user for a planet to search and passes to find_planet_by_name method | ||
def planet_details | ||
puts "\nFor which planet would you like details?" | ||
chosen_planet = gets.chomp | ||
find_planet_by_name(chosen_planet) | ||
end | ||
|
||
# method that searches for planet and returns that planet's summary | ||
def find_planet_by_name(search_planet_name) | ||
@planets.each do |planet| | ||
if search_planet_name.upcase == planet.name.upcase | ||
return planet.summary | ||
end | ||
end | ||
return "\nThere is no planet by that name." | ||
end | ||
|
||
# method to add a new planet | ||
def add_new_planet | ||
puts "\nWhat is the name of this new planet?" | ||
new_name = gets.chomp | ||
|
||
puts "\nWhat is the color of this new planet?" | ||
new_color = gets.chomp | ||
|
||
puts "\nHow much does this new planet weigh in kilograms?" | ||
new_weight = gets.chomp.to_i | ||
while new_weight < 0 | ||
puts "\nThe weight cannot be less than 0. Please enter another value." | ||
new_weight = gets.chomp.to_i | ||
end | ||
|
||
puts "\nHow far is this new planet from the sun in kilometers?" | ||
new_distance = gets.chomp.to_i | ||
while new_distance < 0 | ||
puts "\nThe distance cannot be less than 0. Please enter another value." | ||
new_distance = gets.chomp.to_i | ||
end | ||
|
||
puts "\nWhat is a fun fact about this new planet?" | ||
new_fact = gets.chomp | ||
|
||
new_planet = Planet.new(new_name, new_color, new_weight, new_distance, new_fact) | ||
add_planet(new_planet) | ||
|
||
puts "\nThe new planet, #{new_name}, was added to the list." | ||
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.
In the interest of keeping things to a single responsibility, I would move the methods that do any sort of puts or chomp into main.rb