Java SE 8 API documentation

Last modification: 14/11/16

  1. The Movable interface.

    Write a public geometry.Movable interface. It declares a move() method that takes two integer distances (vertical and horizontal) as arguments. It has no return value.

  2. The Figure interface.

    Write a public geometry.Figure interface. It extends the above Movable interface and the java.lang.Comparable<Figure> interface with the methods below.

    1. An area() that calculates the area of the figure.

    2. A show() that returns the string representation of the figure.

    3. A default implementation of the method compareTo() of the Comparable interface. The default implementation compares two figures based on their areas. The greater figure has greater area.

  3. The Circle class.

    Write a public geometry.Circle class that represents a circle. The class implements the methods of the interface Figure.

    1. Declare three private int fields, the radius and the coordinates of the center of the circle respectively. Make the radius a read-only field using final.

    2. Define a constructor which takes the initial values of the fields and initializes them.

    3. Define the methods of the interface Figure. These are move(), area() and show().

      The show() may produce the following result: Circle at (2,4) radius 5.

  4. The Square class.

    Write a public geometry.Square class which represents a square. The class also implements the methods of the interface Figure.

    1. Declare three private int fields, the size of sides and the coordinates of the upper left corner. Make the size of sides a read-only field using final.

    2. Define a constructor which takes the initial values of the fields and initializes them.

    3. Implement the methods of the interface Figure. These are move(), area() and show().

      The show() may produce the following result: Square at (2,0) side 4.

  5. The FigureDemo class.

    Write a FigureDemo class outside of the geometry package.

    1. Define a static method largest() which returns the figure with largest area from a sequence of figures. The largest() accepts a ArrayList and a LinkedList as well, so it takes a List as argument.

      Use the compareTo() method of the interface Figure to select the largest figure, and an Iterator to iterate over the list.

    2. Write a main() method to test your largest() method. Initialize a List variable with a LinkedList object and add some figures to it. Print the largest figure to the output.