forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 48
Ports_Myriam #44
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
MyriamWD
wants to merge
4
commits into
Ada-C11:master
Choose a base branch
from
MyriamWD: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_Myriam #44
Changes from all commits
Commits
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,89 @@ | ||
| require "awesome_print" | ||
| require_relative "planet" | ||
| require_relative "solar_system" | ||
|
|
||
| def main | ||
| option = "" | ||
| solar_system_name = "Puppy Kingdom" | ||
| solar_system = SolarSystem.new(solar_system_name) | ||
| cybertron = Planet.new("Cybertron", "Silver", 10234, 890890, "Autobots don't live there anymore - see Transformers") | ||
| arrakis = Planet.new("Arrakis", "Orange", 52345234, 12, "it is not a planet of arrays - see Dune") | ||
| pa = Planet.new("P-apes", "Purple", 8999333, 5, "Apes RUlE!! - see... you know this one, don't you?") | ||
| planet_express = Planet.new("Planet-express", "Lot of them", 234, 12, "it is mailing company from the future.") | ||
| solar_system.add_planet(cybertron) | ||
| solar_system.add_planet(arrakis) | ||
| solar_system.add_planet(pa) | ||
| solar_system.add_planet(planet_express) | ||
| puts "\n-------- Welcome to Planets --------" | ||
| while option != "5" | ||
| puts "\nWhat would you like to do next? | ||
| 1. List Planets | ||
| 2. Planet Details | ||
| 3. Add a Planet | ||
| 4. Calculate Distance | ||
| 5. Exit " | ||
| option = gets.chomp.capitalize | ||
|
|
||
| case option | ||
| when "1" | ||
| list = solar_system.list_planets | ||
| puts list | ||
| puts "\nEnter to continue..." | ||
| gets.chomp | ||
| when "2" | ||
| puts "\nPlease, tell me the name of the planet..." | ||
| planet_name = gets.chomp.capitalize | ||
| match = false | ||
| found_planet = solar_system.find_planet_by_name(planet_name, match) | ||
| if found_planet == false | ||
| puts "Planet not found :(" | ||
| else | ||
| puts found_planet.summary | ||
| end | ||
| puts "\nEnter to continue..." | ||
| gets.chomp | ||
| when "3" | ||
| puts "\nPlease input the following information to create a planet..." | ||
| puts "- Name:" | ||
| name = gets.chomp.capitalize | ||
| puts "- Color:" | ||
| color = gets.chomp.downcase | ||
| puts "- Mass (Kg):" | ||
| mass = gets.chomp.to_f | ||
| while mass <= 0 | ||
| puts "Please enter a number higher than 0... | ||
| - Mass (Kg):" | ||
| mass = gets.chomp.to_f | ||
| end | ||
| puts "- Distance from #{solar_system_name} (Kms):" | ||
| distance_from_sun_km = gets.chomp.to_f | ||
| while distance_from_sun_km <= 0 | ||
| puts "Please enter a number higher than 0... | ||
| - Distance from #{solar_system_name} (Kms):" | ||
| distance_from_sun_km = gets.chomp.to_f | ||
| end | ||
| puts "- Fun Fact" | ||
| fun_fact = gets.chomp.downcase | ||
| planet = Planet.new(name, color, mass, distance_from_sun_km, fun_fact) | ||
| solar_system.add_planet(planet) | ||
| puts "\nEnter to continue..." | ||
| gets.chomp | ||
| when "4" | ||
| puts "\nCalculate Planets Distance" | ||
| temporary_distance = 0 | ||
| 2.times do |i| | ||
| puts "What is the planet N #{i + 1}?" | ||
| planet_q = gets.chomp.capitalize | ||
| temporary_distance = (temporary_distance - solar_system.distance_between(planet_q)).abs | ||
| end | ||
| puts " The distance between the two planets is: #{temporary_distance}Kms" | ||
| puts "\nEnter to continue..." | ||
| gets.chomp | ||
| when "5" | ||
| puts "Bye..." | ||
| 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,26 @@ | ||
|
|
||
| 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 "\nIn a galaxy far away (not start wars) | ||
| there is a planet called #{name}. It appears | ||
| to be #{color} and its mass is #{mass_kg}. | ||
| The distance between #{name} and the | ||
| sun is #{distance_from_sun_km} kms. | ||
| Something that you might not know is that #{fun_fact}." | ||
| end | ||
| end | ||
|
|
||
| # Question: Why do we puts in main but not in Planet#summary? | ||
| # Because in Planet#summary we are modeling the behavior and state | ||
| # for the new instances of the class. In main we actually | ||
| # use the state and behavior |
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,47 @@ | ||
|
|
||
|
|
||
| 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 | ||
| string = "\nPlanets orbitting #{star_name}\n" | ||
| @planets.each_with_index do |planet, index| | ||
| string += "#{index + 1}. #{planet.name}\n" | ||
| end | ||
| return string | ||
| end | ||
|
|
||
| def find_planet_by_name(planet_name, match) | ||
| @planets.each do |planet| | ||
| # return planet.name == planet_name ? planet : false | ||
| # return planet if planet.name == planet_name | ||
| if planet.name == planet_name | ||
| match = true | ||
| return planet | ||
|
|
||
| # else | ||
| # return | ||
| end | ||
| end | ||
| if match == false | ||
| return false | ||
| end | ||
| end | ||
|
|
||
| def distance_between(planet_q) | ||
|
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. This isn't calculating the distance between two planets. Instead it's calculating the distance between a planet and the sun, which is already served by a method in the |
||
| @planets.each do |planet| | ||
| if planet.name == planet_q | ||
| return planet.distance_from_sun_km | ||
| end | ||
| 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 could simply: