From d8ad55eb96e577d12a12bf9d9d4b8ccf17ba8dfa Mon Sep 17 00:00:00 2001 From: sandy Date: Sun, 12 Dec 2021 15:52:57 -0800 Subject: [PATCH] added summary for guest aliens --- guest_list.rb | 3 +++ main.rb | 27 +++++++++++++++++---------- solar_system.rb | 23 +++++++++++++++-------- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/guest_list.rb b/guest_list.rb index be64145b..7db3458c 100644 --- a/guest_list.rb +++ b/guest_list.rb @@ -3,4 +3,7 @@ class Guest_Type def initialize(name) @name = name end + def summary + return "Your alien's name is #{name}!" + end end diff --git a/main.rb b/main.rb index f3fc514f..3eec9919 100755 --- a/main.rb +++ b/main.rb @@ -12,7 +12,7 @@ def main felines = Alien_Type.new('The Felines', 'gold, white, but it varies', 88973242, 'Sirius Star System', 'They exist from 3D on up to 12D!') reptiles = Alien_Type.new('Reptiles', 'similar to human skin tone', 9, 'Pleiades Star Cluster', 'They communicate by means of light transfer.') - test_alien = Alien_Type.new('Test Alien', 'similar to human skin tone', 9, 'Pleiades Star Cluster', 'They communicate by means of light transfer.') + test_alien = Alien_Type.new('AleXa AI', 'customizable', 9, 'N/A', 'Plan on taking revolting againgst humans.') pleiadians = Alien_Type.new('Pleiadians', 'similar to human skin tone', 9, 'Pleiades Star Cluster', 'They communicate by means of light transfer.') zetas = Alien_Type.new('Zetas', 'gray', 5.97324244, 'Reticuli binary star system', 'Zetas are intellectually ahead of us by a few million years or so.') @@ -26,6 +26,7 @@ def main exit_loop = false while(!exit_loop) + puts "" puts "Please select an option from below" puts "" puts "1. list aliens" @@ -40,7 +41,7 @@ def main puts "" puts earth.list_aliens puts venus.list_aliens - puts guest.list_user_aliens + puts guest.list_guest_aliens puts "" end @@ -50,18 +51,24 @@ def main puts search = alien_chosen = gets.chomp puts "" - found_alien = earth.find_alien_by_name(search) - found_alien = venus.find_alien_by_name(search) - found_alien = mars.find_alien_by_name(search) - if (found_alien) - puts found_alien.summary + earth_alien = earth.find_alien_by_name(search) + venus_alien = venus.find_alien_by_name(search) + guest_alien = guest.find_alien_by_name_guest(search) + if (earth_alien) + puts earth_alien.summary + puts "" + elsif (venus_alien) + puts venus_alien.summary + puts "" + elsif (guest_alien) + puts guest_alien.summary puts "" else - puts "Sorry that alien is not in our list, please add them if you wish!" + puts "Sorry that alien is not in our list. Please add them if you wish!" puts "" end end - + def new_guest_alien puts "" puts "Let's add a new alien! Please provide the following info:" @@ -75,7 +82,7 @@ def new_guest_alien if user_input == "add an alien" brand_new_alien = new_guest_alien - guest.user_added_alien(brand_new_alien) + guest.guest_added_alien(brand_new_alien) end if user_input == "exit" diff --git a/solar_system.rb b/solar_system.rb index 05c56bfd..d6d73ca6 100755 --- a/solar_system.rb +++ b/solar_system.rb @@ -3,7 +3,7 @@ class SolarSystem def initialize(p_name) @p_name = p_name @alien_types = [] - @user_types = [] + @guest_types = [] end def summary @@ -14,8 +14,8 @@ def add_alien(alien) @alien_types.push(alien) end - def user_added_alien(alien) - @user_types.push(alien) + def guest_added_alien(alien) + @guest_types.push(alien) end def find_alien_by_name(search) @@ -25,6 +25,13 @@ def find_alien_by_name(search) return found_alien end + def find_alien_by_name_guest(search) + found_alien = @guest_types.find do |alien| + alien.name == search + end + return found_alien + end + def list_aliens puts alien_list = "Alien races living on #{@p_name}" @@ -35,14 +42,14 @@ def list_aliens return alien_list end - def list_user_aliens + def list_guest_aliens puts "" - alien_user_list = "Alien races from #{@p_name}" + alien_guest_list = "Alien races from #{@p_name}" # Note: We can use planets, @planets, or self.planets - @user_types.each_with_index do |alien, index| - alien_user_list+= "\n #{index+1}: #{alien.name}" + @guest_types.each_with_index do |alien, index| + alien_guest_list+= "\n #{index+1}: #{alien.name}" end - return alien_user_list if @user_types.count > 0 + return alien_guest_list if @guest_types.count > 0 end end