Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA assignment Count alligators and clone sheep Console Counting alligators...

ID: 666169 • Letter: J

Question

JAVA assignment

Count alligators and clone sheep

Console

Counting alligators...

1 alligator

2 alligator

3 alligator

Counting sheep...

1 Blackie

2 Blackie

1 Dolly

2 Dolly

3 Dolly

1 Blackie

Operation

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.

Specifications

Create an interface named Countable that can be used to count an object. This interface should include these methods:

void incrementCount()
void resetCount()
int getCount()
String getCountString()

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.

Explanation / Answer

Counting alligators...

1 alligator

2 alligator

3 alligator

Counting sheep...

1 Blackie

2 Blackie

1 Dolly

2 Dolly

3 Dolly

1 Blackie Press

any key to continue . . . Operation This application uses an Alligator class that implements a Countable interface todisplay Alligator objects as shown above.

This application uses a Sheep class that implements a Countable interface and theCloneable interface to display and clone Sheep objects as shown above.

pecifications Create an interface named Countable that can be used to count an object. Thisinterface should include these methods: void incrementCount()void resetCount()int getCount()String getCountString() Create a class named Alligator that implements the Countable interface.

This classshould include an instance variable that stores the count and a method that returns theformatted count. Create a class named CountUtil. This class should include a static method that letsyou 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 anAlligator 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 thefirst sheep, changes the name, and counts it 3 times, and (c) counts the first sheepagain 1 time.

Implementing the Relatable Interface

Here is the Rectangle class that was presented in the Creating Objects section, rewritten to implement Relatable.