Create a class called dog that implements the comparable


First, create a class called Dog that implements the Comparable interface. Dog will contain a member variable to hold a name, a constructor that sets up the name, and three methods (getName, compareTo, toString). getName returns the member variable, compareTo works as defined by the Comparable interface, and toString returns the name neatly formatted. Second, you'll compare Dogs by their names.

Include a main method in Dog that asks the user to input ten names and generates ten Dog objects. A blank name should not be used to create an object. Using the compareTo method, determine first and last dog among them and print them. Do not simply sort the Dog data.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Create a class called dog that implements the comparable
Reference No:- TGS02374508

Now Priced at $15 (50% Discount)

Recommended (96%)

Rated (4.8/5)