forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Ports - Kim #31
Open
Kimberly-Fasbender
wants to merge
14
commits into
Ada-C11:master
Choose a base branch
from
Kimberly-Fasbender: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.
+128
−0
Open
Ports - Kim #31
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d34fc37
Added Planet Class with a constructor
Kimberly-Fasbender 61af727
Moved planet.rb to lib folder
Kimberly-Fasbender acef472
Added main.rb
Kimberly-Fasbender 7357622
Added main method & summary instance method
Kimberly-Fasbender 90396bf
Correcting Syntax and spelling
Kimberly-Fasbender ac4a02a
Added SolarSystem class
Kimberly-Fasbender 952101e
Added add_planet method to SolarSystem class
Kimberly-Fasbender 13f5152
Added list_planets method to SolarSystem class
Kimberly-Fasbender d6c323b
Updated driver code
Kimberly-Fasbender d7a2beb
Added method find_planet_by_name to SolarSystem class
Kimberly-Fasbender 3aaec26
Added control loop
Kimberly-Fasbender c9efcca
Added planet details option
Kimberly-Fasbender c3adf19
Added add planet option to control panel
Kimberly-Fasbender 3f21c25
Add comments and clean up code
Kimberly-Fasbender 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,59 @@ | ||
require_relative "planet" | ||
require_relative "solar_system" | ||
|
||
# method that creates an instance of a solar system and adds instances of planets to it | ||
# also, creates a control panel for the user | ||
def main | ||
# creating an instance of a solar system | ||
big_ol_pupper = SolarSystem.new("Big Ol Pupper") | ||
|
||
# creating instances of planets | ||
waffles = Planet.new("Waffles", "\'maple syrup\' brown", 3.555e23, 1.273e12, "It is the only known " \ | ||
"planet to be smothered in fried chicken") | ||
cuddles = Planet.new("Cuddles", "soft velvet grey", 9.973e30, 0.000002, "This planet loves the Big Ol " \ | ||
"Pupper so much that it can\'t get close enough to it") | ||
whiskey = Planet.new("Whiskey", "rich amber", 4.342e27, 3.473e13, "This planet has been aged for" \ | ||
"billions of years in a giant cosmic cedar barrel") | ||
bear = Planet.new("Bear", "jet black", 5.342e20, 5.342e14, "Contains more hugs per capita than any other" \ | ||
"known planet") | ||
pancake = Planet.new("Pancake", "light brown", 7.888e24, 3.342e5, "There is no planet fluffier or " \ | ||
"flatter than Pancake") | ||
|
||
# adding instances of planets to an array | ||
big_ol_pupper.add_planet(waffles) | ||
big_ol_pupper.add_planet(cuddles) | ||
big_ol_pupper.add_planet(whiskey) | ||
big_ol_pupper.add_planet(bear) | ||
big_ol_pupper.add_planet(pancake) | ||
|
||
# control panel that allows users to list planets, look at planet detials, add planets, or exit program | ||
selection = "list planets" | ||
while ["list planets", "planet details", "add planet", "exit"].include?(selection) | ||
print "\nWhat would you like to do next? (list planets, planet details, add planet, or exit): " | ||
selection = gets.chomp.downcase | ||
|
||
until ["list planets", "planet details", "add planet", "exit"].include?(selection) | ||
print "Whoopsie Daisy! Please select an option from the list (list planets, planet details, add planet, or exit): " | ||
selection = gets.chomp.downcase | ||
end | ||
|
||
case selection | ||
when "list planets" | ||
puts "\n#{big_ol_pupper.list_planets}" | ||
when "planet details" | ||
print "\nWhat planet would you like to see details for?: " | ||
planet_details = gets.chomp.downcase | ||
found_planet = big_ol_pupper.find_planet_by_name(planet_details) | ||
puts "\n====== #{found_planet.name} ======" | ||
puts "#{found_planet.summary}" | ||
when "add planet" | ||
big_ol_pupper.add_new_planet | ||
puts "\n========= New planet has been added to the Big Ol Pupper solar system! <3 ==========" | ||
when "exit" | ||
break | ||
end | ||
end | ||
end | ||
|
||
# runs main method | ||
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,20 @@ | ||
# class that creates instances of planets | ||
class Planet | ||
attr_accessor :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact | ||
|
||
# constructor that initializes a name, color, mass (kg), distance from the sun (km), and fun fact | ||
# about each instance of a planet | ||
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 prints out a summary of a planet instance | ||
def summary | ||
return "#{@name} is a #{@color} planet with a mass of #{@mass_kg} kg and is #{@distance_from_sun_km} " \ | ||
"km from the sun! DID YOU KNOW: #{@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,49 @@ | ||
# class that is responsible for keeping track of a collection of instances of Planet | ||
class SolarSystem | ||
# creating methods to read/return star_name & planets | ||
attr_reader :star_name, :planets | ||
|
||
# constructor that accepts and stores star_name in an instance variable | ||
# and assigns an empty array to the instance variable planets | ||
def initialize(star_name) | ||
@star_name = star_name | ||
@planets = [] | ||
end | ||
|
||
# method that adds a planet to the @planets array | ||
def add_planet(planet) | ||
@planets << planet | ||
end | ||
|
||
# method that returns a list of all planets in a given solar system | ||
def list_planets | ||
planet_list = "Doggos orbiting #{@star_name}: " | ||
@planets.each_with_index { |planet, i| planet_list += "\n#{i + 1}. #{planet.name}" } | ||
return planet_list | ||
end | ||
|
||
# method that returns the instance of a planet when given a string of its name | ||
def find_planet_by_name(planet_string) | ||
@planets.each do |planet| | ||
if planet.name == planet_string.capitalize | ||
return planet | ||
end | ||
end | ||
end | ||
|
||
# method that adds a new planet to the existing solar system | ||
def add_new_planet | ||
print "\nWhat is the name of the planet you would like to add?: " | ||
new_planet = gets.chomp.capitalize | ||
print "What is the color of the planet your are adding?: " | ||
new_planet_color = gets.chomp.downcase | ||
print "What is the mass of the planet you are adding (in kg)?: " | ||
new_planet_mass = gets.chomp | ||
print "What is the distance of this planet from Big Ol Pupper (in km)?: " | ||
new_planet_distance = gets.chomp | ||
print "What is a fun fact about this planet?: " | ||
new_planet_fun_fact = gets.chomp.capitalize | ||
new_planet_final = Planet.new(new_planet, new_planet_color, new_planet_mass, new_planet_distance, new_planet_fun_fact) | ||
add_planet(new_planet_final) | ||
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.
I suggest moving this method to
main.rb
to separate the user interface role from the role tracking and organizing planets.