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.

Quiz

Which of the following statements is not true?

A. All the methods in an interface are abstract.
B. A class can implement just the methods of an interface it needs.
C. An interface can contain static constants.
D. A class can implement multiple interfaces.
E. A class can inherit another class and implement an interface.

A method that accepts an interface as an argument can accept any object that:

A. implements that interface
B. defines the same methods as the interface
C. implements the interface or defines the same methods as the interface
D. is created from that interface

A variable that stores an object that implements an interface can be declared as which of the following data types?

A. The class that defines the object
B. The interface that the object implements
C. Any subclass of the class that defines the object
D. All of the above
E. a and c only

When you code a class that implements an interface, NetBeans can:

A. throw an UnsupportedOperationException
B. generate the declaration for the inteface
C. generate all of the method declarations for the methods defined by the interface
D. generate the constants of the interface

The Cloneable interface:

A. clones an object
B. can only be used with mutable objects
C. indicates if an object can be cloned
D. indicates if an object has been cloned

The Comparable interface:

A. compares two objects
B. indicates if two objects have the same type
C. indicates if an object has overridden the equals method of the Object class
D. indicates if an object has overridden the toString method of the Object class

How does a mutable object differ from an immutable object?

A. A mutable object can be changed, and an immutable object can't be changed.
B. A mutable object can be cloned, and an immutable object can't be cloned.
C. A mutable object can be compared with other objects, and an immutable object can't be compared with other objects.

To include a class in a package, you:

A. code an import statement as the first statement of the class
B. code a package statement as the first statement in the class file
C. code the name of the package in the class declaration

Which of the following is not true about generated Java documentation?

A. It indicates the package that a class belongs to.
B. It lists all public methods of the class.
C. It includes the code that implements each documented method.
D. It lets you view classes by package.

Which of the following is an advantage of coding two or more classes in the same file?

A. You have fewer java files to manage.
B. You have fewer class files to manage.
C. It's easier to find the source code for a class.
D. It makes it easier to reuse a class.
Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.