-
Notifications
You must be signed in to change notification settings - Fork 48
Ports - Shamira #41
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
base: master
Are you sure you want to change the base?
Ports - Shamira #41
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| require_relative "solar_system" | ||
| require_relative "planet" | ||
|
|
||
| def main | ||
| sol_system = SolarSystem.new("Sol") | ||
| gem_homeland = Planet.new("Gem Homeland", "crystal", 78939, 287200, "Home of the Crystal Gems.") | ||
| sol_system.add_planet(gem_homeland) | ||
|
|
||
| venus = Planet.new("Venus", "purple", 78939, 2000, "The brightest object in our solar system after the sun and the moon. ") | ||
| sol_system.add_planet(venus) | ||
|
|
||
| earth = Planet.new("Earth", "blue", 100.25, 5000, "I live here!") | ||
| sol_system.add_planet(earth) | ||
|
|
||
| mars = Planet.new("Mars", "red", 78939, 2000, "John Jones is from there") | ||
| sol_system.add_planet(mars) | ||
|
|
||
| jupiter = Planet.new("Jupiter", "yellow", 78939, 2000, "The fastest rotating planet in the solar system.") | ||
| sol_system.add_planet(jupiter) | ||
|
|
||
| saturn = Planet.new("Saturn", "purple with rings", 78939, 2000, "My fav planet!") | ||
| sol_system.add_planet(saturn) | ||
|
|
||
| uranus = Planet.new("Uranus", "orange", 78939, 2000, "lol") | ||
| sol_system.add_planet(uranus) | ||
|
|
||
| neptune = Planet.new("Neptune", "green", 78939, 2000, "Not to be confused with the King of Bikini Bottom.") | ||
| sol_system.add_planet(neptune) | ||
|
|
||
| list = sol_system.list_planets | ||
|
|
||
| puts sol_system.list_planets_one | ||
| #will return a summary of the planet you put in the argument | ||
| # sol_system.find_planet_by_name_two("maRs").summary | ||
|
|
||
| puts "Would you like a list of planets, planet details, to add a planet, or to exit?" | ||
| puts "Enter (list), (details), (add), or (exit)." | ||
| puts "Enter List to continue or exit to end the program" | ||
|
|
||
| # gets user input | ||
|
|
||
| loop do | ||
| list = sol_system.list_planets | ||
| input = gets.chomp.downcase | ||
| break if input == "exit" | ||
|
|
||
| case input | ||
| when "list" | ||
| puts list | ||
| when "details" | ||
| puts "What planet do you want details for?" | ||
| details = gets.chomp.downcase | ||
| puts sol_system.find_planet_by_name_two(details).summary | ||
| when "add" | ||
| sol_system.new_planet | ||
| puts sol_system.list_planets | ||
| end | ||
| break | ||
| end | ||
|
|
||
| puts "Goodbye!" | ||
| end | ||
|
|
||
| main | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| 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 the color #{color}, weighs #{mass_kg}kg, and is #{distance_from_sun_km}km from the sun. Fun fact: #{fun_fact} " | ||
| end | ||
| end | ||
|
|
||
| earth = Planet.new("Earth", "green", 100.25, 5000, "I live here!") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| require "minitest/autorun" | ||
| require "minitest/reporters" | ||
| require_relative "planet" | ||
|
|
||
| Minitest::Reporters.use! | ||
|
|
||
| describe "planet" do | ||
| it "will return a string" do | ||
| home_planet = earth.summary | ||
| earth = Planet.new("Earth", "green", 100.25, 5000, "I live here!") | ||
|
|
||
| expect(home_planet).must_be_instance_of String | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| class SolarSystem | ||
| attr_reader :star_name, :planets | ||
|
|
||
| def initialize(star_name) | ||
| @star_name = star_name | ||
| @planets = [] | ||
| end | ||
|
|
||
| # Create a method add_planet, | ||
| #which will take an instance of Planet as a parameter and add it to the list of planets. | ||
| def add_planet(planet) #Planet.name | ||
| #iterate through each Planet.name and put it in the @planets array. | ||
| @planets << planet | ||
| end | ||
|
|
||
| def list_planets | ||
| result = "Planets orbitting:\n" | ||
| planet_names = @planets.map do |planet| | ||
| planet.name | ||
| end | ||
| planet_names.each_with_index do |name, index| | ||
| result += "#{index + 1}. #{name}\n" | ||
| end | ||
| return result | ||
| # @planets.name specify that you're searching the name | ||
| end | ||
|
|
||
| def list_planets_one | ||
|
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 method seems a duplication of the above |
||
| result = "Planets orbitting:\n" | ||
| @planets.each_with_index do |planet, index| | ||
| result += "#{index + 1}. #{planet.name}\n" | ||
| end | ||
| return result | ||
| end | ||
|
|
||
| def find_planet_by_name_two(name) | ||
| return @planets.find do |planet| | ||
| planet.name.downcase == name.downcase | ||
| end | ||
| end | ||
|
|
||
| def new_planet | ||
|
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 would be better as a method which takes a |
||
| puts "Add planet name:" | ||
| name = gets.chomp.downcase | ||
| puts "Add color:" | ||
| color = gets.chomp | ||
| puts "Add mass in kg:" | ||
| mass_kg = gets.chomp.to_i | ||
| puts "Distance from the sun?" | ||
| distance_from_sun_km = gets.chomp.to_i | ||
| puts "What is a fun fact about your planet?" | ||
| fun_fact = gets.chomp | ||
| user_input_planet = (Planet.new(name, color, mass_kg, distance_from_sun_km, fun_fact)) | ||
| # planet(user_input_planet) | ||
| # puts sol_system.new_planet.summary | ||
| add_planet(user_input_planet) | ||
| end | ||
| end | ||
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.
This break is always going to make the loop exit.