W 8 Additional

1. Create a program useful for modelling files and folders, as it follows:

  • Interface Item contains
a method named getContent that does not have parameters and returns a String
  • Class File implements the interface Item and contains
a String attribute named information; the content of this attribute is specific to each file
a constructor for setting the value of the attribute
getContent returns the value of the attribute (information)
  • Class Folder implements the interface Item and contains
an attribute named entries whose type is Item[]. This attribute is specific to each instance of this class and is initialised with an empty array
a method for adding a file OR a folder into the existing array
getContent calls getContent for each stored item in the attribute whose type is Item[] and the result is a concatenation of the results provided by each called method

Implement the mentioned classes and create inside a main method some instances of each class. At least one folder should contain more folders.

2. Create a program useful for modeling different types of figures. Currently the system contains Circles, Squares and Triangles. Each figure has a color, contains a method for computing its perimeter and provides a method for printing. Printing each figure shows the message with the content: Figure Type – Color – Perimeter.

We consider that two figures have the same content if they have the same type and the same perimeter.

Each circle has a radius, each square has a side and each rectangle has three sides. All the modeled figures have corresponding setters (methods for modifying their characteristics (color, radius, side)).

When a figure is instantiated, it is attached (added) to an Observer. An Observer is a class that cannot be instantiated more than once. An instance of Observer provides the following services:

  • a method for adding a figure (regardless of the type of the figure) into an array, the array being an attribute of class Observer.
  • a method for notifying the observer that the state of an object that is contained have been modified. This method is called by each figure, when at least a characteristic of the figure has been changed (via the setters methods) and it prints all the figures that are contained by the observer.
  • A method for printing all the contained figures.

Implement the mentioned classes and create inside a main method at least one figure of each mentioned type and modify at least one attribute of each figure.