• This application uses an Alligator class that implements a Countable interface to display Alligator objects as shown above.
• This application uses a Sheep class that implements a Countable interface and the Cloneable interface to display and clone Sheep objects as shown above.
• Create an interface named Countable that can be used to count an object. This interface should include these methods:
• Create a class named Alligator that implements the Countable interface. This class should include an instance variable that stores the count and a method that returns the formatted count.
• Create a class named CountUtil. This class should include a static method that lets you count any Countable objects a specified number of times. For example:
public static void count(Countable c, int maxCount)
• Create a class named CountTestApp that uses the CountUtil class to count an Alligator object 3 times as shown above.
• Create a class named Sheep that implements the Countable and Cloneable interfaces. This class should include an instance variable that stores the count and the name of the sheep, and it should provide methods that can set and get the name of the sheep.
• Modify the CountTestApp class so it (a) counts the first sheep 2 times, (b) clones the first sheep, changes the name, and counts it 3 times, and (c) counts the first sheep again 1 time.
define one Interface, Countable; and four classes, Alligator, Sheep, CountUtil, and CountTestApp. We also need to use the Cloneable interface and that Interface is already defined in the java.lang package.
Both the Sheep class and the Alligator class must implement the Countable Interface. Sheep must also implement the Cloneable interface.
Also note that both the Sheep and Alligator classes have count instance variables. This variable keeps track of how many times the object has been “counted”. Sheep also have names so sheep can have names like Dolly and Blackie. Alligators don’t so there is no Ollie Alligator.
The CountUtil class has one method, count, that accepts two parameters, the Countable type that is to be counted and the number of times it is to be counted. This method should use the getCountString method of the Countable object. The count method should reset the Countable’s count variable and then “count” it the number of times specified by the second parameter received by the method. What this method should do is to display information about the Countable being counted and the number of times it is counted.
The CountTestApp does not really do very much. It simply creates objects (Alligators and then Sheep) and sends those objects along with the number of times the object is to be counted as parameters to the count method of the CountUtil class.
Create a file named CH09PR91 with the classes Alligator, Sheep, and CountUtil and the interface Countable in it. None of these should be public.
Create a class named CountTestApp that tests methods of the other classes primarily by creating instances of Alligator and Sheep and sending them as parameters to the count method of the CountUtil class. You should be able to use any CountTestApp to test your Alligator, Sheep, and CountUtil classes and Countable interface.Attachments