Question: In this program we will be using inheritance, abstract classes, the Comparable interface and writing to a file. You will also need to create a

In this program we will be using inheritance, abstract classes, the Comparable interface and writing to a file. You will also need to create a custom exception which you must use and catch.

Create an abstract class Animal. This class should contain instance variables as follows:

String name must be at least 1 character but not more than 10 characters.

int paws must be from 0 to 4

methods

abstract speak() returns a String

toString() returns name and number of paws

getters/setters

constructors as needed

Should implement the Comparable interface. Compare on the name of the animal

Create a Dog class that extends Animal

Implement the abstract speak method return Woof, woof!

Create a toString() method should print the type of animal add the Animal toString() and append the results of the speak method.

Create a Cat class that extends Animal

Implement the abstract method return Meow.

Create a toString() method should print the type of animal add the Animal toString() and append the results of the speak method.

Create an InvalidAnimalException which will be used if an invalid animal is entered.

Create an AnimalTester class.

Create an array of Animals at least 5 Animals.

Using a Random assignment Assign a mixture of Cats and Dogs to the array.

You will need a method to allow users to enter the name and number of paws. This cannot be static.

Write the original array to a file.

Sort the array.

Write the sorted array to the same file.

Read the file and print the results.

You must use your custom exception to tell the user if their entry is invalid.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!