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

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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Petjava public class Pet private String nameownerNamespeciesbreed private double ageweight public Pe... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!

Related Book