Question
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
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.
Sample Output: Thank you!
output SER200 HW11 (run) Variables Action Items run Please enter the dog's name or a blank line to quit Fido Please enter the dog's name or a blank line to quit Skippy Please enter the dog's name or a blank line to quit Fuzzy Please enter the dog's name or a blank line to quit Bailey please enter the dog's name or a blank line to quit Max Please enter the dog's name or a blank line to quit First Dog [name Bailey] Last Dog [name-Skippyl
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