forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 44
Selam's Solar System code Wave 3 #35
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
SelamawitA
wants to merge
1
commit into
Ada-C9:master
Choose a base branch
from
SelamawitA: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
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,118 @@ | ||
| class SolarSystem | ||
| # initialized SolarSystem object with an array of Planet objects. | ||
| attr_reader:solar_sys_age | ||
| def initialize(user_planet,solar_sys_age) | ||
| @planets = user_planet | ||
| @solar_sys_age = solar_sys_age | ||
| end | ||
| # adds a Planet object to an array of Planets | ||
| def add_planet(new_planet) | ||
| @planets.push(new_planet) | ||
| return @planets | ||
| end | ||
| # iterates through array of Planet objects and displays a formatted list to user. | ||
| def list_of_planets() | ||
| counter = 0 | ||
| planet_names = "" | ||
| @planets.each do |planet| | ||
| planet_names += "\n#{counter+1}. #{planet.planet_details}" | ||
| counter+=1 | ||
| end | ||
| return planet_names | ||
| end | ||
|
|
||
| end | ||
|
|
||
|
|
||
|
|
||
| class Planet | ||
| attr_reader:name, :radius_mi, :distance_frm_sun, :num_moons, :num_suns, :year_in_days | ||
|
|
||
| # initialize Planet object with a mixture of string and integer attributes | ||
| def initialize(name, radius_mi, distance_frm_sun, num_moons, num_suns, year_in_days) | ||
| @name = name | ||
| @radius_mi = radius_mi | ||
| @distance_frm_sun = distance_frm_sun | ||
| @num_moons = num_moons | ||
| @num_suns = num_suns | ||
| @year_in_days = year_in_days | ||
| end | ||
| # returns formatted list of a planet's detail. | ||
| def planet_details () | ||
| return planet_detail = "\n#{@name} Planet Information : \nRadius (mi): #{@radius_mi}\nDistance from Sun (mi): #{@distance_frm_sun}\nNumber of moons: #{@num_moons}\nNumber of suns: #{@num_moons}\nNumber of days in year: #{@year_in_days}\n" | ||
| end | ||
| end | ||
|
|
||
|
|
||
| def menu() | ||
| # Built-in planet list | ||
| earth = Planet.new("Earth", 3959, 92960000, 1, 1, 365) | ||
| jupiter = Planet.new("Jupiter", 43441, 483800000, 67, 1, 4300) | ||
| venus = Planet.new("Venus", 3760 , 67000000, 0, 1, 225) | ||
| planet_of_the_puppies = Planet.new("Planet of the Puppies", 3959, 336000000, 15, 38, 180) | ||
|
|
||
| # Built-in solar-system | ||
| a_solar_system = [earth,jupiter,venus,planet_of_the_puppies] | ||
| new_solar_system = SolarSystem.new(a_solar_system,400000000) | ||
|
|
||
| puts "\nEnter (A) if you'd like to learn information about some planets.\n\n" | ||
| puts "Enter (B) if you'd like to input some new information to help us grow!\n\n" | ||
| puts "Or press any key to exit." | ||
| print "\nMenu choice: " | ||
| menu_choice = gets.chomp.upcase | ||
| # loop to direct and keep user within menu | ||
| while menu_choice == 'A' || menu_choice == 'B' | ||
| if menu_choice == 'A' | ||
| puts "\nHere's a list of the planets you can pick from.\n" | ||
| counter = 1 | ||
| # prints a formatted list to the user. | ||
| a_solar_system.each do |planet| | ||
| puts "#{counter}. #{planet.name}" | ||
| counter+=1 | ||
| end | ||
| print "Planet choice: " | ||
| user_planet = gets.chomp | ||
| check_in_list_counter = 0 | ||
|
|
||
| # compares user input to current planet list. | ||
| a_solar_system.each do |planet| | ||
| if planet.name.upcase == user_planet.upcase | ||
| print planet.planet_details | ||
| else | ||
| check_in_list_counter+=1 | ||
| end | ||
| end | ||
|
|
||
| if check_in_list_counter == a_solar_system.length | ||
| puts "\nSorry not in the list :/ " | ||
| end | ||
| elsif menu_choice == 'B' | ||
| print "\nEnter your planets name:" | ||
| user_planet = gets.chomp | ||
| print "\nEnter your planet's radius: " | ||
| user_radius = gets.chomp | ||
| print "\nEnter your planet's distance from the sun: " | ||
| user_dist_frm_sun = gets.chomp | ||
| print "\nEnter how many moons your planet has: " | ||
| user_num_moons = gets.chomp | ||
| print "\nEnter how many suns your planet has: " | ||
| user_num_suns = gets.chomp | ||
| print "\nEnter how many days make a year: " | ||
| user_day_in_year = gets.chomp | ||
|
|
||
| user_planet = Planet.new(user_planet,user_radius,user_dist_frm_sun,user_num_moons,user_num_suns,user_day_in_year) | ||
|
|
||
| new_solar_system.add_planet(user_planet) | ||
| puts "\nYour planet has been added!" | ||
| end | ||
| puts "\nEnter (A) if you'd like to learn information about some planets.\n\n" | ||
| puts "Enter (B) if you'd like to input some new information to help us grow!\n\n" | ||
| puts "Press any key to exit." | ||
| print "Menu choice:" | ||
| menu_choice = gets.chomp.upcase | ||
| end | ||
| puts "\nThank you, good-bye!" | ||
|
|
||
| end | ||
|
|
||
| menu() | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
A small thing, but important. This syntax is wrong because you need a space between
attr_readerand:nameso it should be: