Answered step by step
Verified Expert Solution
Question
00
1 Approved Answer
Implement the function processAnimals ( ) that takes as a parameter the name of an input file. The input file contains zero or more lines
Implement the function processAnimals that takes as a parameter the name of an input file. The input file contains zero or more lines with the format: species, language, age where species is a string representing an animal's species, language is a string representing an animal's language, and age is an integer representing an animal's age. The items on each line are separated by commas. The processAnimals function should read all lines in the file, creating an Animal object for each line and placing the object into a list. The function also displays to the screen the result of calling speak on each object in the list it created. The function returns the list of objects created or an empty list if the file didn't contain any lines. Don't forget to close the input file. If your function cannot open the input file it should display a message to that effect and return an empty list. The information below shows how you would call the function processAnimals on an example file. The file empty.txt is empty and the file none.txt does not exist. Please note that your implementation should work on any file with the specified format, not just the one provided as a test case:
Implement the function processAnimals that takes as a parameter the name of an input file. The
input file contains zero or more lines with the format: species, language, age where species is a
string representing an animal's species, language is a string representing an animal's language, and
age is an integer representing an animal's age. The items on each line are separated by commas.
The processAnimals function should read all lines in the file, creating an Animal object for each
line and placing the object into a list. The function also displays to the screen the result of calling
speak on each object in the list it created. The function returns the list of objects created or an
empty list if the file didn't contain any lines. Don't forget to close the input file. If your function
cannot open the input file it should display a message to that effect and return an empty list. The
information below shows how you would call the function processAnimals on an example file.
The file empty.txt is empty and the file none.txt does not exist. Please note that your
implementation should work on any file with the specified format, not just the one provided as a
test case:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started