forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 48
Ports - Kasey #37
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
kaseea
wants to merge
6
commits into
Ada-C11:master
Choose a base branch
from
kaseea: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
Ports - Kasey #37
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c7db9e9
wave 1 step one and two
kaseea 825352e
wave 1 complete, optional exercises later
kaseea a0de29c
added a solar_system class
kaseea facd625
required sections through wav 2
kaseea d8ac9e8
wave 3
kaseea b690605
fixes a keystroke error while saving that I didn't notice
kaseea 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,55 @@ | ||
| require_relative "planet" | ||
| require_relative "solar_system" | ||
|
|
||
| def main | ||
| solar_system = SolarSystem.new("Sol") | ||
| earth = Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") | ||
| solar_system.add_planet(earth) | ||
| venus = Planet.new("Venus", "green", 6.972e24, 2.496e8, "moody") | ||
| solar_system.add_planet(venus) | ||
| astra = Planet.new("Astra", "silver", 5, 23, "Marvel Universe planet") | ||
| solar_system.add_planet(astra) | ||
| ego = Planet.new("Ego", "green", 124234, 325623, "Marvel bioverse") | ||
| solar_system.add_planet(ego) | ||
| namek = Planet.new("Namek", "blue-green", 35435472, 23513541, "Dragon Ball world with lots of water and grass") | ||
| solar_system.add_planet(namek) | ||
|
|
||
| def wanna_add_planet() | ||
| puts "please add a planet: what is the planets name?" | ||
| name = gets.chomp | ||
| puts "and color?" | ||
| color = gets.chomp | ||
| puts "and mass?" | ||
| mass_kg = gets.chomp | ||
| puts "and distance from the sun?" | ||
| distance_from_sun_km = gets.chomp | ||
| puts "and please share a fun fact" | ||
| fun_fact = gets.chomp | ||
| planet = Planet.new(name, color, mass_kg, distance_from_sun_km, fun_fact) | ||
| return planet | ||
| end | ||
|
|
||
| loop do | ||
| puts "do you want to" | ||
| puts "1. list planets" | ||
| puts "2. planet details" | ||
| puts "3. add planet" | ||
| puts "4. exit" | ||
| answer = gets.chomp | ||
| if answer.to_i == 1 || answer == "list planets" | ||
| list = solar_system.list_planets | ||
| puts list | ||
| elsif answer.to_i == 2 || answer == "planet details" | ||
| puts "what planet do you want more info on" | ||
| planet = gets.chomp | ||
| found_planet = solar_system.find_planet_by_name(planet) | ||
| puts found_planet.summary | ||
| elsif answer.to_i == 3 || answer == "add planet" | ||
| solar_system.add_planet(wanna_add_planet()) | ||
| else | ||
| break | ||
| end | ||
| end | ||
| 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,15 @@ | ||
| 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 | ||
|
|
||
| def summary | ||
| return "#{name}: is #{color}, weighs #{mass_kg}, is #{distance_from_sun_km} km from the sun and #{fun_fact}" | ||
| 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,27 @@ | ||
| 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() | ||
| planet_list = "Planets orbiting #{star_name}: \n" | ||
| @planets.each_with_index do |planet, i| | ||
| planet_list << "#{i + 1}: #{planet.name} \n" | ||
| end | ||
| return planet_list | ||
| end | ||
|
|
||
| def find_planet_by_name(planet_name) | ||
| found = @planets.find { |planet| | ||
| planet.name.upcase == planet_name.upcase | ||
| } | ||
| return found | ||
| 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 do some sort of check to see if you could find the planet before calling
.summary