W 8 Additional
1. Create a program useful for modelling files and folders, as it follows:
- Interface Item contains
- Class File implements the interface Item and contains
- Class Folder implements the interface Item and contains
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.