-
Notifications
You must be signed in to change notification settings - Fork 29
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
finished lab #7
base: master
Are you sure you want to change the base?
finished lab #7
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,26 @@ | ||
|
||
class Client | ||
|
||
attr_accessor :name, :number_of_children, :age, :gender, :pets | ||
|
||
def initialize(name, age, gender, number_of_children) | ||
@name = name | ||
@age = age | ||
@gender = gender | ||
@number_of_children = number_of_children | ||
@pets = {} | ||
end | ||
|
||
def to_s | ||
return "#{@name} is a #{@age} year old #{@gender} with #{@number_of_children} kids and #{pets.length} pets" | ||
# expect(@client.to_s).to eql("Beth is a 30 year old female with 3 kids and 0 pets") | ||
end | ||
|
||
def display_pets | ||
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. Be careful with indentation! Come see me if you want some assistance on this. |
||
pets_name = [] | ||
@pets.each do |k, v| pets_name.push(v.to_s) | ||
end | ||
return pets_name.join("\n") | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,79 @@ | ||
require 'pry' | ||
require 'rainbow' | ||
# require 'rainbow' | ||
require_relative 'data' | ||
require_relative 'animal' | ||
require_relative 'client' | ||
require_relative 'shelter' | ||
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. The require relatives for "animal", "client", and "shelter" are not needed because these files are required in data.rb, and will be imported with line 3 in this file. |
||
|
||
response = #set this equal to something | ||
while response != 'Q' | ||
##Fill in code here | ||
puts "Welcome to the HappiTails Rescue Shelter!" | ||
|
||
puts "Please pick an option: \n | ||
(A) Display Animals \n | ||
(B) Display Clients \n | ||
(C) Create Animals \n | ||
(D) Create Clients \n | ||
(E) Adopt an animal \n | ||
(F) Return an animal \n | ||
(Q) Quit" | ||
response = gets.chomp.upcase | ||
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. Good way to catch and equalize responses from the user. |
||
|
||
while response != "Q" | ||
case response | ||
when "A" | ||
$shelter.display_animals | ||
when "B" | ||
$shelter.display_clients | ||
when "C" | ||
puts "Enter Name" | ||
name = gets.chomp.capitalize.to_s | ||
puts "Enter age" | ||
age = gets.chomp.to_i | ||
puts "Enter gender" | ||
gender = gets.chomp.to_s | ||
puts "Enter species" | ||
species = gets.chomp.to_s | ||
new_animal = Animal.new(name, age, gender,species) | ||
$shelter.animals[name] = new_animal | ||
when "D" | ||
puts "Enter your name" | ||
name = gets.chomp.to_s | ||
puts "Enter your age" | ||
age = gets.chomp.to_i | ||
puts "Enter your gender" | ||
gender = gets.chomp.to_s | ||
puts "How many children do you have" | ||
children = gets.chomp.to_i | ||
new_client = Client.new(name, age, gender, children) | ||
$shelter.clients[name] = new_client | ||
when "E" | ||
puts "What is your name?" | ||
client_name = gets.chomp.capitalize.to_s | ||
puts "Which animal do you want to adopt?" | ||
animal_name = gets.chomp.capitalize.to_s | ||
$shelter.animals.delete(animal_name) | ||
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. Hmm, the adoption part seems incomplete and that was one of the most challenging parts of the lab. Can you tell what your logic behind it was? Try attempting it again, if you have time. |
||
when "F" | ||
#puts "NO RETURNS. ALL ADOPTIONS ARE FINAL." | ||
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. Ha! |
||
puts "Which animal do you want to return?" | ||
animal_name = gets.chomp.capitalize.to_s | ||
# new_animal = Animal.new(name) | ||
$shelter.animals[name] = animal_name | ||
when "Q" | ||
end | ||
puts "Please pick an option: \n | ||
(A) Display Animals \n | ||
(B) Display Clients \n | ||
(C) Create Animals \n | ||
(D) Create Clients \n | ||
(E) Adopt an animal \n | ||
(F) Return an animal \n | ||
(Q) Quit" | ||
response = gets.chomp.upcase | ||
end | ||
|
||
|
||
# response = #set this equal to something | ||
# while response != 'Q' | ||
# ##Fill in code here | ||
|
||
response = #set this equal to something | ||
end | ||
# response = #set this equal to something | ||
# end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class Shelter | ||
|
||
attr_accessor :name, :address, :animals, :clients | ||
|
||
def initialize(name, address) | ||
@name = name | ||
@address = address | ||
@animals = {} | ||
@clients = {} | ||
end | ||
|
||
def to_s | ||
return "#{@name} shelter at #{@address} has #{@animals.count} animals and #{@clients.count} people" | ||
end | ||
|
||
def display_clients | ||
$shelter.clients.each {|k, v| puts (v.to_s) + "\n"} | ||
#return "#{@name} is a #{@age} year old #{@gender} 3 kids and 0 pets" | ||
#return "Beth is a 30 year old female with 3 kids and 0 pets" | ||
# client_arr = [] | ||
# @clients.each do |k,v| | ||
# client_arr.push(v.to_s) | ||
# end | ||
# client_arr.join("\n") | ||
end | ||
|
||
def display_animals | ||
$shelter.animals.each {|k,v| puts (v.to_s) + "\n"} | ||
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. Try to use other variable names besides "k" and "v", like "animal" or "name" (or whatever the key and value actually describes). This helps with code readability and reminds of what key and value actually are. |
||
# animals_arr = [] | ||
# @animals.each do |k, v| | ||
# animals_arr.push(v.to_s) | ||
# end | ||
# animals_arr.join("\n") | ||
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.
Glad you're (commenting and) adding tests throughout your project. It really helps guide the code.