Joomla Vorlagen by Website Hosting

PL1 - 4th laboratory

lab04.zip

1. Create an interface Valuable that contains the getValue (): double method and implement a class AverageComputer, which has a method for counting the average value of objects in the array it receives as a parameter. Objects are of the same type - Valuable. Make sure you can use AverageComputer to calculate the average size of an area of shapes - rectangle, ellipse, triangle.

2. The project uses CanvasManager to address some of the drawbacks of the previous rendering solution. It can display all objects that implement the Paintable interface. Objects are rendered after they are registered using the add method. Modify the Triangle class to work with the CanvasManager mechanism - use the fillPolygon method in the MyGraphics class to render.

3. Connect the triangle and ellipse creation - ManipulationPanelController.createShape method.

4. Implement the option to delete shapes.

  • To do this, create a Clickable interface that includes the "isInBound (double x, double y): boolean" method, which returns "true" if the given coordinate is inside the object.
  • In the ManipulationPanelController.mousePressed method, add a treatment that if the deleteRB button is selected then all the registered shapes are processed (an array of subjects is returned by method registeredSubjects from CanvasManager)  and if a shape is Clickable (use operator instanceof) then it will verify that we clicked it (isInBounds) and eventually it will be removed.

 

UML

pl1 lab07 01

Average computer.

 

pl1 lab07 02

Graphic application

Solution

lab04-solution.zip

Homework:

Allow working with your shapes - drawing, deleting.

Create a class that will implement the motion algorithm. It will include a method that gets the object as a parameter, the new position, the length, and the time in ms. In this method there will be an algorithm that moves the object from the starting point to the ending in steps, between which there will be a delay specified as the parameter "time". The amount of displacement (the length of the vector by which the displacement occurs) in one step is determined by the "length" parameter. Define a suitable type for this purpose - an interface that allows you to determine the current position and set a new position.

Note: The motion implementing method will actually be a "template method" that calls abstract methods from the interface of the object being passed - see the "Template method" design pattern https://www.kozusznik.cz/resources/msps/gof/hires/pat5jfso.htm.

In contrast, as the pattern is defined, the "template method" is in a different class than the called abstract methods.