From e4ece64560704ba448e938c20697bed8e2825aa3 Mon Sep 17 00:00:00 2001 From: Kate Pond Date: Thu, 8 Feb 2018 16:09:19 -0800 Subject: [PATCH 01/14] creates the first working code for Solar System --- planets.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 planets.rb diff --git a/planets.rb b/planets.rb new file mode 100644 index 00000000..7fe9c056 --- /dev/null +++ b/planets.rb @@ -0,0 +1,29 @@ +class SolarSystem + + attr_accessor :planets + + def initialize + @planets = Array.new + end + + def add_new_planet(new_planet) + @planets.push(new_planet) + end + + def list_planets + string = "" + @planets.each do |planet| + string += "#{@planets.index(planet) + 1}. #{planet}\n" + end + return string + end +end + +kates = SolarSystem.new + +kates.add_new_planet("Some Planet") +kates.add_new_planet("Hoth") +kates.add_new_planet("Earth") +kates.add_new_planet("GAH Planet") + +puts kates.list_planets From b0286ecb694fb37fe11884b8e7805f3bcc39d336 Mon Sep 17 00:00:00 2001 From: Kate Pond Date: Thu, 8 Feb 2018 16:26:29 -0800 Subject: [PATCH 02/14] refactors to initalize planets that already exsist --- planets.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/planets.rb b/planets.rb index 7fe9c056..a37bd8c3 100644 --- a/planets.rb +++ b/planets.rb @@ -2,28 +2,26 @@ class SolarSystem attr_accessor :planets - def initialize - @planets = Array.new + def initialize(planets = ["Some Planet", "Hoth", "Earth", "GAH"]) + @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 - string = "" + list = "" @planets.each do |planet| - string += "#{@planets.index(planet) + 1}. #{planet}\n" + list += "#{@planets.index(planet) + 1}. #{planet}\n" end - return string + return list end end kates = SolarSystem.new -kates.add_new_planet("Some Planet") -kates.add_new_planet("Hoth") -kates.add_new_planet("Earth") -kates.add_new_planet("GAH Planet") +kates.add_new_planet("Out-of-this-World") puts kates.list_planets From 29169179b386df6e3e864a62ecd59485cfca0db1 Mon Sep 17 00:00:00 2001 From: Kate Pond Date: Thu, 8 Feb 2018 20:09:20 -0800 Subject: [PATCH 03/14] turns planets into hashes with values --- planets.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/planets.rb b/planets.rb index a37bd8c3..8fc31fc9 100644 --- a/planets.rb +++ b/planets.rb @@ -2,7 +2,7 @@ class SolarSystem attr_accessor :planets - def initialize(planets = ["Some Planet", "Hoth", "Earth", "GAH"]) + def initialize(planets = [{}]) @planets = planets end @@ -10,6 +10,7 @@ def initialize(planets = ["Some Planet", "Hoth", "Earth", "GAH"]) def add_new_planet(new_planet) @planets.push(new_planet) end + # method that returns a list of strings def list_planets list = "" @@ -20,8 +21,16 @@ def list_planets end end -kates = SolarSystem.new +# 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]) -kates.add_new_planet("Out-of-this-World") +# adds newly found planet to SolarSystem +nunu_planet = { name: "ConeHead Planet", color: "off-white"} +kates.add_new_planet(nunu_planet) +# prints a list of the planets puts kates.list_planets From 4a3b6ed1e3eb6980933425605defe6a3e63a1869 Mon Sep 17 00:00:00 2001 From: Kate Pond Date: Thu, 8 Feb 2018 22:18:07 -0800 Subject: [PATCH 04/14] creates wave1 code... or at least I think it does --- planets.rb => wave1.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) rename planets.rb => wave1.rb (78%) diff --git a/planets.rb b/wave1.rb similarity index 78% rename from planets.rb rename to wave1.rb index 8fc31fc9..c8fbde19 100644 --- a/planets.rb +++ b/wave1.rb @@ -22,14 +22,24 @@ def list_planets end # creates planets with attributes -out_of_this_world = { name: "Out-of-this-World", color: "blue"} -another_planet = { name: "NTP", color: "green"} +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: "ConeHead Planet", color: "off-white"} +nunu_planet = { + name: "Remulak", + color: "off-white" +} + kates.add_new_planet(nunu_planet) # prints a list of the planets From e9fc548c0930cdbf298769d491cc5e3998707089 Mon Sep 17 00:00:00 2001 From: Kate Pond Date: Fri, 9 Feb 2018 11:13:36 -0800 Subject: [PATCH 05/14] creates Planet class --- wave2.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 wave2.rb diff --git a/wave2.rb b/wave2.rb new file mode 100644 index 00000000..9df12c34 --- /dev/null +++ b/wave2.rb @@ -0,0 +1,26 @@ +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}\n + Age: #{@age}\n + Distance From Sun: #{@distance_from_sun}\n + Year Length: #{@year_length}\n + Inhabitants: #{@inhabitants} + " + return list + end +end + +kate = Planet.new("Something", 45, "6789mi", "789days", "Cone Heads") + +puts kate.list_attributes From f3e2292600a6ea4e4a24de5be35e4f7b9bf596d7 Mon Sep 17 00:00:00 2001 From: Kate Pond Date: Fri, 9 Feb 2018 11:28:13 -0800 Subject: [PATCH 06/14] adds SolarSystem Class to Wave 2 --- wave2.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/wave2.rb b/wave2.rb index 9df12c34..2851bc2c 100644 --- a/wave2.rb +++ b/wave2.rb @@ -21,6 +21,35 @@ def list_attributes end end +class SolarSystem + + attr_accessor :planets + + def initialize(planets = Array.new) + @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 + 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(planet= [kate, pond]) + +puts kate_system.list_planets From 61320d7046accfe314d7db262a5d355fea6db3e9 Mon Sep 17 00:00:00 2001 From: Kate Pond Date: Sat, 10 Feb 2018 08:32:56 -0800 Subject: [PATCH 07/14] creates working code that needs a marjor overhaul --- wave2.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/wave2.rb b/wave2.rb index 2851bc2c..bb9b5841 100644 --- a/wave2.rb +++ b/wave2.rb @@ -10,13 +10,7 @@ def initialize(name, age, distance_from_sun, year_length, inhabitants) end def list_attributes - list = " - Name: #{@name}\n - Age: #{@age}\n - Distance From Sun: #{@distance_from_sun}\n - Year Length: #{@year_length}\n - Inhabitants: #{@inhabitants} - " + list = "Name: #{@name}, Age: #{@age}, Distance From Sun: #{@distance_from_sun}, Year Length: #{@year_length}, Inhabitants: #{@inhabitants}" return list end end @@ -26,6 +20,7 @@ class SolarSystem attr_accessor :planets def initialize(planets = Array.new) + planet = Planet.new(@name, @age, @distance_from_sun, @year_length, @inhabitants) @planets = planets end @@ -38,10 +33,11 @@ def add_new_planet(new_planet) def list_planets list = "" @planets.each do |planet| - list += "#{@planets.index(planet) + 1}. #{planet}\n" + list += "#{@planets.index(planet) + 1}. #{planet.list_attributes}" end return list end + end kate = Planet.new("Something", 45, "6789mi", "789days", "Cone Heads") @@ -50,6 +46,8 @@ def list_planets puts kate.list_attributes -kate_system = SolarSystem.new(planet= [kate, pond]) +kate_system = SolarSystem.new([kate, pond]) + +the_planets = kate_system.list_planets -puts kate_system.list_planets +p the_planets From 6b22931964c66e21edc143c0b0aa13def59bdb43 Mon Sep 17 00:00:00 2001 From: Kate Pond Date: Sat, 10 Feb 2018 17:14:21 -0800 Subject: [PATCH 08/14] Classes work --- wave3.rb | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 wave3.rb diff --git a/wave3.rb b/wave3.rb new file mode 100644 index 00000000..bfcbc012 --- /dev/null +++ b/wave3.rb @@ -0,0 +1,80 @@ +# 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. + +# Planet Class +class Planet + attr_accessor :name, :age, :distance_from_sun, :year_length, :inhabitants + + # create a planet methods + def initialize(planet_attributes) + @name = planet_attributes[:name] + @age = planet_attributes[:age] + @distance_from_sun = planet_attributes[:distance_from_sun] + @year_length = planet_attributes[:year_length] + @inhabitants = planet_attributes[:inhabitants] + end + + # list planet attributes method + 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 + # 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}\n" + # list += "#{planet.name.index + 1}. #{planet.name}\n" + end + return list + end +end + +planets_array = [] +#### test new planets +kate = { + name: "Something", + age: 45, + distance_from_sun: "6789mi", + year_length: "789days", + inhabitants: "Cone Heads" +} + +random = { + name: "Random", + age: 4, + distance_from_sun: "85mi", + year_length: "9days", + inhabitants: "Bradlies" +} + +kate = Planet.new(kate) +random = Planet.new(random) + +planets_array = [kate, random] + +kates = SolarSystem.new(planets_array) + +# puts kates.list_planets +# +# puts random.list_attributes +#### + + +puts "Which planet would you like to look at? Please select one of the following +planets in the solar system: " + +puts "Would you like to make your own planet?" From f826fdd48b4d18f2272380b860270425f2d66e20 Mon Sep 17 00:00:00 2001 From: Kate Pond Date: Sun, 11 Feb 2018 10:15:16 -0800 Subject: [PATCH 09/14] redefines solar system and temp fix for linter issues --- wave2.rb | 8 ++++---- wave3.rb | 50 ++++++++++++++++++++++++++------------------------ 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/wave2.rb b/wave2.rb index bb9b5841..b67e7e6d 100644 --- a/wave2.rb +++ b/wave2.rb @@ -20,14 +20,14 @@ class SolarSystem attr_accessor :planets def initialize(planets = Array.new) - planet = Planet.new(@name, @age, @distance_from_sun, @year_length, @inhabitants) + # 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 + # def add_new_planet(new_planet) + # @planets.push(new_planet) + # end # method that returns a list of strings def list_planets diff --git a/wave3.rb b/wave3.rb index bfcbc012..2a52f411 100644 --- a/wave3.rb +++ b/wave3.rb @@ -5,20 +5,20 @@ # Planet Class class Planet - attr_accessor :name, :age, :distance_from_sun, :year_length, :inhabitants + attr_accessor :name, :age, :size, :visitor_count, :inhabitants # create a planet methods def initialize(planet_attributes) @name = planet_attributes[:name] @age = planet_attributes[:age] - @distance_from_sun = planet_attributes[:distance_from_sun] - @year_length = planet_attributes[:year_length] + @size = planet_attributes[:size] + @visitor_count = planet_attributes[:visitor_count] @inhabitants = planet_attributes[:inhabitants] end # list planet attributes method def list_attributes - list = "Name: #{@name}, Age: #{@age}, Distance From Sun: #{@distance_from_sun}, Year Length: #{@year_length}, Inhabitants: #{@inhabitants}" + list = "Name: #{@name}\nAge: #{@age}\nSize: #{@size}\nVisitor Count: #{@visitor_count}\nInhabitants: #{@inhabitants}\n" return list end end @@ -45,36 +45,38 @@ def list_planets planets_array = [] #### test new planets -kate = { - name: "Something", - age: 45, - distance_from_sun: "6789mi", - year_length: "789days", - inhabitants: "Cone Heads" +katmai = { + name: "Katmai National Park", + age: 38, + size: "16,564.09 km", + visitor_count: "37,818", + inhabitants: "Bears" } -random = { - name: "Random", - age: 4, - distance_from_sun: "85mi", - year_length: "9days", - inhabitants: "Bradlies" +grand_canyon = { + name: "Grand Canyon National Park", + age: 99, + size: "5,969,811", + visitor_count: "9days", + inhabitants: "Bison" } -kate = Planet.new(kate) -random = Planet.new(random) +katmai = Planet.new(katmai) +grand_canyon = Planet.new(grand_canyon) -planets_array = [kate, random] +planets_array = [katmai, grand_canyon] -kates = SolarSystem.new(planets_array) +national_parks = SolarSystem.new(planets_array) -# puts kates.list_planets +# puts national_parks.list_planets # -# puts random.list_attributes +# puts grand_canyon.list_attributes #### +puts "Welcome to the National Park Universe!" + +puts "Would you like to look at the charcaterists of a planet already in the solar system, or would out like to create a new planet?" +puts national_parks.list_planets -puts "Which planet would you like to look at? Please select one of the following -planets in the solar system: " puts "Would you like to make your own planet?" From 1a7c942033ce7e6beb132226348f62dcbe85da2f Mon Sep 17 00:00:00 2001 From: Kate Pond Date: Sun, 11 Feb 2018 18:58:01 -0800 Subject: [PATCH 10/14] creates mvp... working code nothing flashy --- wave3.rb | 143 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 113 insertions(+), 30 deletions(-) diff --git a/wave3.rb b/wave3.rb index 2a52f411..f12807d7 100644 --- a/wave3.rb +++ b/wave3.rb @@ -3,28 +3,22 @@ # planet and view information about it. # Allow your user to add their own planet. -# 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] +# mixins +class String + # mixin to allow to check for numeric strings + def numeric? + Float(self) != nil rescue false end - - # list planet attributes method - def list_attributes - list = "Name: #{@name}\nAge: #{@age}\nSize: #{@size}\nVisitor Count: #{@visitor_count}\nInhabitants: #{@inhabitants}\n" - return list + # 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 @@ -36,33 +30,100 @@ def list_planets list = "" @planets.each do |planet| counter += 1 - list += "#{counter}. #{planet.name}\n" - # list += "#{planet.name.index + 1}. #{planet.name}\n" + 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 -planets_array = [] -#### test new planets +### 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 = "Name: #{@name.each_first_letters}\nAge: #{@age}\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 "What is the name of the planet? " + new_planet[:name] = gets.chomp.downcase + + print "How old is #{new_planet[:name].each_first_letters}? " + 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 = { - name: "Katmai National Park", + name: "katmai national park", age: 38, size: "16,564.09 km", visitor_count: "37,818", - inhabitants: "Bears" + inhabitants: "bears" } grand_canyon = { - name: "Grand Canyon National Park", + name: "grand canyon national park", age: 99, size: "5,969,811", - visitor_count: "9days", - inhabitants: "Bison" + visitor_count: "5,969,811", + inhabitants: "bison" } -katmai = Planet.new(katmai) -grand_canyon = Planet.new(grand_canyon) +planets_array = [] + +#### test new planets +katmai = Planet.new({ + name: "katmai national park", + age: 38, + size: "16,564.09 km", + visitor_count: "37,818", + inhabitants: "bears" +}) + +grand_canyon = Planet.new({ + name: "grand canyon national park", + age: 99, + size: "5,969,811", + visitor_count: "5,969,811", + inhabitants: "bison" +}) planets_array = [katmai, grand_canyon] @@ -74,9 +135,31 @@ def list_planets #### puts "Welcome to the National Park Universe!" - -puts "Would you like to look at the charcaterists of a planet already in the solar system, or would out like to create a new planet?" +puts "\nWould you like to look at the characteristics of a planet already in the solar system, or would out like to create a new planet?" 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 + +if input == planets_array.count + 1 # if input is to create a new planet + new_planet = create_planet + national_parks.add(new_planet) + puts "\nA new planet called #{new_planet.name.each_first_letters} has been created and saved to the solar system" +else # list characteristics of chosen planet + puts planets_array[input - 1].list_attributes +end + + -puts "Would you like to make your own planet?" +# # if the user input is one more than the list of planets, then they want to create a plant +# if input == (planets_array.length + 1) || input.include?("new", "create") +# # create new planet +# end From 61f5d7f7f41bee35c71428123490b59287c7a96a Mon Sep 17 00:00:00 2001 From: Kate Pond Date: Sun, 11 Feb 2018 19:34:26 -0800 Subject: [PATCH 11/14] fixes minor formatting issues --- wave3.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/wave3.rb b/wave3.rb index f12807d7..0410e812 100644 --- a/wave3.rb +++ b/wave3.rb @@ -71,7 +71,7 @@ def create_planet print "What is the name of the planet? " new_planet[:name] = gets.chomp.downcase - print "How old is #{new_planet[:name].each_first_letters}? " + 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}? " @@ -125,17 +125,16 @@ def create_planet inhabitants: "bison" }) +# creates an array of exisiting planets planets_array = [katmai, grand_canyon] +# create national park solar system national_parks = SolarSystem.new(planets_array) -# puts national_parks.list_planets -# -# puts grand_canyon.list_attributes -#### - +### Start User interface puts "Welcome to the National Park Universe!" -puts "\nWould you like to look at the characteristics of a planet already in the solar system, or would out like to create a new planet?" +puts "\nWould you like to look at the characteristics of a planet already" +puts " in the National Park solar system, or would out like to create a new planet?" puts national_parks.list_planets print "\nPlease make a selection: " @@ -143,7 +142,7 @@ def create_planet # evaluates user input while input.to_i > planets_array.count + 1 || !input.numeric? - print "That is an invalid selection. Please try again." + print "That is an invalid selection. Please try again: " input = gets.chomp end @@ -152,14 +151,15 @@ def create_planet if input == planets_array.count + 1 # if input is to create a new planet new_planet = create_planet national_parks.add(new_planet) - puts "\nA new planet called #{new_planet.name.each_first_letters} has been created and saved to the solar system" + puts "\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 puts planets_array[input - 1].list_attributes end -# # if the user input is one more than the list of planets, then they want to create a plant +# # if the user input is one more than the list of planets, then they want to create a planet # if input == (planets_array.length + 1) || input.include?("new", "create") # # create new planet # end From 9c0991b9e732e307cd575d984ce21129a5578140 Mon Sep 17 00:00:00 2001 From: Kate Pond Date: Sun, 11 Feb 2018 19:47:57 -0800 Subject: [PATCH 12/14] creates exit program dialog and code --- wave3.rb | 62 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/wave3.rb b/wave3.rb index 0410e812..70968936 100644 --- a/wave3.rb +++ b/wave3.rb @@ -132,31 +132,55 @@ def create_planet national_parks = SolarSystem.new(planets_array) ### Start User interface -puts "Welcome to the National Park Universe!" -puts "\nWould you like to look at the characteristics of a planet already" -puts " in the National Park solar system, or would out like to create a new planet?" -puts national_parks.list_planets +quit = false -print "\nPlease make a selection: " -input = gets.chomp + puts "Welcome to the National Park Universe!" -# evaluates user input -while input.to_i > planets_array.count + 1 || !input.numeric? - print "That is an invalid selection. Please try again: " +while !quit + puts "\nWould you like to look at the characteristics of a planet alreadyin the" + puts " National Park solar system, or would out like to create a new planet?" + puts national_parks.list_planets + + print "\nPlease make a selection: " input = gets.chomp -end -input = input.to_i + # 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 -if input == planets_array.count + 1 # if input is to create a new planet - new_planet = create_planet - national_parks.add(new_planet) - puts "\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 - puts planets_array[input - 1].list_attributes -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 planets_array[input - 1].list_attributes + end + ### starts quit program process + print "\n\nWould you like to try 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 +end # # if the user input is one more than the list of planets, then they want to create a planet From 824d988f6f0be7ee67c08d5ace63aada94595dee Mon Sep 17 00:00:00 2001 From: Kate Pond Date: Sun, 11 Feb 2018 20:41:28 -0800 Subject: [PATCH 13/14] cleans up UI and some code for wave 3 --- wave3.rb | 46 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/wave3.rb b/wave3.rb index 70968936..29b1db54 100644 --- a/wave3.rb +++ b/wave3.rb @@ -59,7 +59,7 @@ def initialize(planet_attributes) # list planet attributes method def list_attributes - list = "Name: #{@name.each_first_letters}\nAge: #{@age}\nSize: #{@size}\nVisitor Count: #{@visitor_count}\nInhabitants: #{@inhabitants}\n" + list = "Age: #{@age} Earth years old\nSize: #{@size}\nVisitor Count: #{@visitor_count}\nInhabitants: #{@inhabitants}\n" return list end end @@ -68,7 +68,7 @@ def list_attributes def create_planet new_planet ={} - print "What is the name of the 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? " @@ -89,40 +89,23 @@ def create_planet end ### End Planet Class -# Exisiting Planets -katmai = { - name: "katmai national park", - age: 38, - size: "16,564.09 km", - visitor_count: "37,818", - inhabitants: "bears" -} - -grand_canyon = { - name: "grand canyon national park", - age: 99, - size: "5,969,811", - visitor_count: "5,969,811", - inhabitants: "bison" -} - planets_array = [] -#### test new planets +# Exisiting Planets katmai = Planet.new({ name: "katmai national park", age: 38, - size: "16,564.09 km", + size: "16,564.09 sq km", visitor_count: "37,818", - inhabitants: "bears" + inhabitants: "Bears" }) grand_canyon = Planet.new({ name: "grand canyon national park", age: 99, - size: "5,969,811", + size: "1,901.972 sq mi", visitor_count: "5,969,811", - inhabitants: "bison" + inhabitants: "Bison" }) # creates an array of exisiting planets @@ -137,8 +120,9 @@ def create_planet puts "Welcome to the National Park Universe!" while !quit - puts "\nWould you like to look at the characteristics of a planet alreadyin the" + 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: " @@ -156,15 +140,16 @@ def create_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" + 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 to try another look at the National Park solar system? (y/n) " + print "\n\nWould you like another look at the National Park solar system? (y/n) " quit_input = gets.chomp.downcase case quit_input @@ -179,11 +164,4 @@ def create_planet quit_input = gets.chomp.downcase end end - ### end end - - -# # if the user input is one more than the list of planets, then they want to create a planet -# if input == (planets_array.length + 1) || input.include?("new", "create") -# # create new planet -# end From 0feb4c08697999e2a4b37454df2d63685d41fd0c Mon Sep 17 00:00:00 2001 From: Kate Pond Date: Sun, 11 Feb 2018 20:45:14 -0800 Subject: [PATCH 14/14] removes moot code --- wave3.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/wave3.rb b/wave3.rb index 29b1db54..b7b72bf4 100644 --- a/wave3.rb +++ b/wave3.rb @@ -89,8 +89,6 @@ def create_planet end ### End Planet Class -planets_array = [] - # Exisiting Planets katmai = Planet.new({ name: "katmai national park",