Question
Each of the following classes will be placed in a separate source file. Create the following artifacts: Animal, with the String attributes name and breed.
Each of the following classes will be placed in a separate source file. Create the following artifacts:
Animal, with the String attributes name and breed.
Cat and Dog are subclasses of Animal.
AnimalI, an interface declaring two methods makeSound and whatAmI that return strings.
Each of the three classes will implement the interface, have a constructor and getter methods for each attribute. I suggest using the Generate option from the Code dropdown menu to generate these boilerplate methods. Also, the Animal class needs a toString method which references the whatAmI and makeSound methods. The Cat and Dog classes should NOT have toString methods.
Finally, a Main class (see below) that will create a Scanner object to read a text file (see example below) containing three fields, separated by commas, type, name, and breed. Depending upon the type (A, C or D), create an Animal or Cat or Dog object and store it in an ArrayList of animals.
After all records have been read, iterate through the ArrayList to print the animal using the toString method.
Dont forget to close the text file.
You should use the best object-oriented techniques you can.
Please, adopt the following technique for all main classes:
public class Main {
public static void main(String[] args) {
new Main().go();
}
private void go() {
}
}
Your main class methods, except the main method, should not be static. Only use static methods for utility methods to be used by multiple classes.
animal.txt
A,name,breed
C,Garfield,calico
C,Puss,siamese
D,Snoopy,beagle
D,Lassie,collie
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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