1.Create a class for pets. There should be fields for name, name of owner, species (dog, cat,...
Fantastic news! We've Found the answer you've been seeking!
Question:
1.Create a class for pets. There should be fields for name, name of owner, species (dog, cat, etc.), breed (basset hound, domestic shorthair, etc.), age (a double), and weight (a double).
2.Create a default constructor that does nothing and a constructor that will initialize all fields using values passed in as parms.
3.Create an equals method that checks for the same name and owner name.
4.Do NOT create any set or get methods.
5.Create a toString method that prints all fields. You can create a multi-line String by including newlines; make sure the String is nicely formatted.
6.Client code/driver code (in a separate class):
- 1.Write a method to read Pets from a file. The method will have one parameter which is an ArrayList. The input file is named pets.dat. The data for each field of Pet will be on a separate line. Read in the fields for a Pet, create a Pet object, and add it to the ArrayList. Read till end of file.
- Write a method to print all Pets in the ArrayList.
- In main, create the ArrayList and call the methods to read Pets and print Pets.
Related Book For
Posted Date: