forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 44
Ampers: Kate Pond (submission to Ada-C9 instead of Ada-Gold) #43
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
Oh-KPond
wants to merge
14
commits into
Ada-C9:master
Choose a base branch
from
Oh-KPond: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
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e4ece64
creates the first working code for Solar System
Oh-KPond b0286ec
refactors to initalize planets that already exsist
Oh-KPond 2916917
turns planets into hashes with values
Oh-KPond 4a3b6ed
creates wave1 code... or at least I think it does
Oh-KPond e9fc548
creates Planet class
Oh-KPond f3e2292
adds SolarSystem Class to Wave 2
Oh-KPond 61320d7
creates working code that needs a marjor overhaul
Oh-KPond 6b22931
Classes work
Oh-KPond f826fdd
redefines solar system and temp fix for linter issues
Oh-KPond 1a7c942
creates mvp... working code nothing flashy
Oh-KPond 61f5d7f
fixes minor formatting issues
Oh-KPond 9c0991b
creates exit program dialog and code
Oh-KPond 824d988
cleans up UI and some code for wave 3
Oh-KPond 0feb4c0
removes moot code
Oh-KPond 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,46 @@ | ||
| class SolarSystem | ||
|
|
||
| attr_accessor :planets | ||
|
|
||
| def initialize(planets = [{}]) | ||
| @planets = planets | ||
| end | ||
|
|
||
| # method to add new planets | ||
| def add_new_planet(new_planet) | ||
| @planets.push(new_planet) | ||
| end | ||
|
|
||
| # method that returns a list of strings | ||
| def list_planets | ||
| list = "" | ||
| @planets.each do |planet| | ||
| list += "#{@planets.index(planet) + 1}. #{planet}\n" | ||
| end | ||
| return list | ||
| end | ||
| end | ||
|
|
||
| # creates planets with attributes | ||
| out_of_this_world = { | ||
| name: "Out-of-this-World", | ||
| color: "blue" | ||
| } | ||
| another_planet = { | ||
| name: "NTP", | ||
| color: "green" | ||
| } | ||
|
|
||
| # creates a new SolarSystem with created planets | ||
| kates = SolarSystem.new([out_of_this_world, another_planet]) | ||
|
|
||
| # adds newly found planet to SolarSystem | ||
| nunu_planet = { | ||
| name: "Remulak", | ||
| color: "off-white" | ||
| } | ||
|
|
||
| kates.add_new_planet(nunu_planet) | ||
|
|
||
| # prints a list of the planets | ||
| puts kates.list_planets |
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,53 @@ | ||
| class Planet | ||
| attr_accessor :name, :age, :distance_from_sun, :year_length, :inhabitants | ||
|
|
||
| def initialize(name, age, distance_from_sun, year_length, inhabitants) | ||
| @name = name | ||
| @age = age | ||
| @distance_from_sun = distance_from_sun | ||
| @year_length = year_length | ||
| @inhabitants = inhabitants | ||
| end | ||
|
|
||
| def list_attributes | ||
| list = "Name: #{@name}, Age: #{@age}, Distance From Sun: #{@distance_from_sun}, Year Length: #{@year_length}, Inhabitants: #{@inhabitants}" | ||
| return list | ||
| end | ||
| end | ||
|
|
||
| class SolarSystem | ||
|
|
||
| attr_accessor :planets | ||
|
|
||
| def initialize(planets = Array.new) | ||
| # new_planet = Planet.new(@name, @age, @distance_from_sun, @year_length, @inhabitants) | ||
| @planets = planets | ||
| end | ||
|
|
||
| # method to add new planets | ||
| # def add_new_planet(new_planet) | ||
| # @planets.push(new_planet) | ||
| # end | ||
|
|
||
| # method that returns a list of strings | ||
| def list_planets | ||
| list = "" | ||
| @planets.each do |planet| | ||
| list += "#{@planets.index(planet) + 1}. #{planet.list_attributes}" | ||
| end | ||
| return list | ||
| end | ||
|
|
||
| end | ||
|
|
||
| kate = Planet.new("Something", 45, "6789mi", "789days", "Cone Heads") | ||
|
|
||
| pond = Planet.new("Pond Planet", 5, "69mi", "7days", "None") | ||
|
|
||
| puts kate.list_attributes | ||
|
|
||
| kate_system = SolarSystem.new([kate, pond]) | ||
|
|
||
| the_planets = kate_system.list_planets | ||
|
|
||
| p the_planets |
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,165 @@ | ||
| # Create an interface where the user can interact | ||
| # with the solar system and be able to select a | ||
| # planet and view information about it. | ||
| # Allow your user to add their own planet. | ||
|
|
||
| # mixins | ||
| class String | ||
| # mixin to allow to check for numeric strings | ||
| def numeric? | ||
| Float(self) != nil rescue false | ||
| end | ||
| # mixin to allow first letter of each word in a string to be capitalized | ||
| def each_first_letters | ||
| self.split.map(&:capitalize).join(' ') | ||
| end | ||
| end | ||
|
|
||
| ### Start Solar System class | ||
| class SolarSystem | ||
| attr_accessor :planets | ||
|
|
||
| # create new solar system | ||
| def initialize(planets_array) | ||
| @planets = planets_array | ||
| end | ||
|
|
||
| # returns a list of strings | ||
| def list_planets | ||
| counter = 0 | ||
| list = "" | ||
| @planets.each do |planet| | ||
| counter += 1 | ||
| list += "#{counter}. #{planet.name.each_first_letters}\n" | ||
| end | ||
|
|
||
| list += "#{counter + 1}. **CREATE NEW PLANET**" | ||
| return list | ||
| end | ||
|
|
||
| # adds a new to the solar system | ||
| def add new_planet | ||
| @planets << new_planet | ||
| end | ||
| end | ||
| ### End Solar System class | ||
|
|
||
| ### Start Planet Class | ||
| class Planet | ||
| attr_accessor :name, :age, :size, :visitor_count, :inhabitants | ||
|
|
||
| # create a planet methods | ||
| def initialize(planet_attributes) | ||
| @name = planet_attributes[:name] | ||
| @age = planet_attributes[:age] | ||
| @size = planet_attributes[:size] | ||
| @visitor_count = planet_attributes[:visitor_count] | ||
| @inhabitants = planet_attributes[:inhabitants] | ||
| end | ||
|
|
||
| # list planet attributes method | ||
| def list_attributes | ||
| list = "Age: #{@age} Earth years old\nSize: #{@size}\nVisitor Count: #{@visitor_count}\nInhabitants: #{@inhabitants}\n" | ||
| return list | ||
| end | ||
| end | ||
|
|
||
| # method to create a new planet | ||
| def create_planet | ||
| new_planet ={} | ||
|
|
||
| print "\nWhat is the name of the planet? " | ||
| new_planet[:name] = gets.chomp.downcase | ||
|
|
||
| print "How old is #{new_planet[:name].each_first_letters} in Earth years? " | ||
| new_planet[:age] = gets.chomp.to_i | ||
|
|
||
| print "What is the size of #{new_planet[:name].each_first_letters}? " | ||
| new_planet[:size] = gets.chomp | ||
|
|
||
| print "How many visitors does #{new_planet[:name].each_first_letters} get? " | ||
| new_planet[:visitor_count] = gets.chomp | ||
|
|
||
| print "Who or what are #{new_planet[:name].each_first_letters} inhabitants? " | ||
| new_planet[:inhabitants] = gets.chomp | ||
|
|
||
| new_planet = Planet.new(new_planet) | ||
|
|
||
| return new_planet | ||
| end | ||
| ### End Planet Class | ||
|
|
||
| # Exisiting Planets | ||
| katmai = Planet.new({ | ||
|
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. interesting |
||
| name: "katmai national park", | ||
| age: 38, | ||
| size: "16,564.09 sq km", | ||
| visitor_count: "37,818", | ||
| inhabitants: "Bears" | ||
| }) | ||
|
|
||
| grand_canyon = Planet.new({ | ||
| name: "grand canyon national park", | ||
| age: 99, | ||
| size: "1,901.972 sq mi", | ||
| visitor_count: "5,969,811", | ||
| inhabitants: "Bison" | ||
| }) | ||
|
|
||
| # creates an array of exisiting planets | ||
| planets_array = [katmai, grand_canyon] | ||
|
|
||
| # create national park solar system | ||
| national_parks = SolarSystem.new(planets_array) | ||
|
|
||
| ### Start User interface | ||
| quit = false | ||
|
|
||
| puts "Welcome to the National Park Universe!" | ||
|
|
||
| while !quit | ||
| print "\nWould you like to look at the characteristics of a planet already in the" | ||
| puts " National Park solar system, or would out like to create a new planet?" | ||
| puts "Here are the planets currently in the solar system!" | ||
| puts national_parks.list_planets | ||
|
|
||
| print "\nPlease make a selection: " | ||
| input = gets.chomp | ||
|
|
||
| # evaluates user input | ||
| while input.to_i > planets_array.count + 1 || !input.numeric? | ||
| print "That is an invalid selection. Please try again: " | ||
| input = gets.chomp | ||
| end | ||
|
|
||
| input = input.to_i # converts input to integer once string "input" is numeric | ||
|
|
||
| # if input is to create a new planet | ||
| if input == planets_array.count + 1 | ||
| new_planet = create_planet | ||
| national_parks.add(new_planet) | ||
| print "\nA new planet called #{new_planet.name.each_first_letters} has been" | ||
| puts " created and saved to the solar system" | ||
| # else list characteristics of chosen planet | ||
| else | ||
| puts "\nHere's the information for #{planets_array[input - 1].name.each_first_letters}" | ||
| puts planets_array[input - 1].list_attributes | ||
| end | ||
|
|
||
| ### starts quit program process | ||
| print "\n\nWould you like another look at the National Park solar system? (y/n) " | ||
| quit_input = gets.chomp.downcase | ||
|
|
||
| case quit_input | ||
| when "y", "yes", "yep", "yea" | ||
| quit = false | ||
| when "n", "nope", "nah" | ||
| print "Thank you for using the visiting the National Park Universe program! Good bye!" | ||
| quit = true | ||
| else | ||
| while !["y", "yes", "yep", "yea", "n", "nope", "nah"].include?(quit_input) | ||
| print "Would you like to try another calulation? (y/n) " | ||
| quit_input = gets.chomp.downcase | ||
| 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.
Another mix-in, nice!