|
# Write a ruby script that uses a nested conditional or case statement to output certain text based on input |
|
|
|
class Dog |
|
attr_accessor :breed |
|
attr_accessor :size |
|
|
|
def initialize(breed, size) |
|
@breed = breed |
|
@size = size |
|
end |
|
end |
|
|
|
puts "Hello, please enter information about your dog." |
|
|
|
print "What breed is your dog (labrador, bulldog, poodle): " |
|
breed = gets.chomp.to_s.downcase |
|
|
|
print "What size is your dog? (small, medium, large): " |
|
size = gets.chomp.to_s.downcase |
|
|
|
dog = Dog.new(breed, size) |
|
puts "------------------------" |
|
|
|
case dog.breed |
|
when "lab", "labrador" |
|
puts "Labradors have a estimated lifespan of 10 to 12 years on average." |
|
|
|
if dog.size == "small" |
|
puts "Your #{dog.breed} is just a puppy, and has a lot of growing to do!" |
|
elsif dog.size == "medium" |
|
puts "Your #{dog.breed} will grow to be bigger still!" |
|
elsif dog.size == "large" |
|
puts "Your #{dog.breed} is an adult." |
|
puts "Many adult female Labradors reach a weight of 55-75lbs and stand 21-22 inches high at the shoulder." |
|
puts "Many adult male Labradors reach a weight of 65-85lbs and stand 22-23 inches at the shoulder" |
|
else |
|
puts "Sorry it appears you mistyped the size" |
|
end |
|
|
|
|
|
when "poodle" |
|
puts "Poodles have an estimated life span of 12-15 years on average." |
|
|
|
if dog.size == "small" |
|
puts "Your #{dog.breed} is just a puppy, and has a lot of growing to do!" |
|
puts "While poodles are one of the smaller dog breeds, they make fantastic companions." |
|
elsif dog.size == "medium" |
|
puts "Your #{dog.breed} is most likely under 5lbs." |
|
elsif dog.size == "large" |
|
puts "An average adult poodle can be anywhere between 5lbs and 8lbs." |
|
else |
|
puts "Sorry it appears you mistyped the size" |
|
end |
|
|
|
when "bulldog", "bull" |
|
puts "Bulldogs have an estimated life span of 8 to 10 years on average." |
|
|
|
if dog.size == "small" |
|
puts "Your #{dog.breed} is just a puppy, and has a lot of growing to do!" |
|
elsif dog.size == "medium" |
|
puts "Your #{dog.breed} will grow to be bigger still!" |
|
elsif dog.size == "large" |
|
puts "Your #{dog.breed} is an adult." |
|
else |
|
puts "Sorry it appears you mistyped the size" |
|
end |
|
|
|
|
|
else |
|
puts "I've never heard of that dog breed before!" |
|
end |
🎱 💯