Lesson 6
Writing simple java applications following OOP principles.
Objectives
- inheritance
- aggergation and composition
- abstract classes
- interfaces
- polimorfism
Documentation
Polimorfismul
Clase abstracte si interfete
Thinking in Java : Chapter 7 - Polimorphism
Diagrama de clase
Implementarea diagramelor UML in Java
Exercises
Exercise 1
Starting from the application presented here add following changes:
- Add Rectangle class, create an object of type Rectangle and add it so that is displayed on the drawing board when the application is run from Main class;
- Add drawing coordinates for shapes so that they can be placed anywhere on the drawing board;
- Add an 'id' attributed for the shapes which to uniquely identify a shape. The 'id' will defined as String and will be added in the Shape clas;
- Add void deleteById(String id) method in the DrawingBoard class so that to be possible to delete a shape by id. Make sure that after a shape is deleted the shape is actually deleted from the JFrame;
- Add the 'fill' attribute which tell if a shape should be drawn filled or not.
Exercise 2
Create UML class diagram for the application developed in Exercise 2.
Exercise 3
Rewrite implementation from exercise 1 and replace abstract class Shape with an interface.
Exercise 4
Write a class that implements the CharSequence interface found in the java.lang package. Write a unit test to validate your implementation.
Exercise 5
Write a program which draw a pyramid. The program must get as input number of the bricks and the size of a brick (high and width in pixels). Program must build the highest possible pyramid with the given resources (number of bricks).
(Optional) Exercise 6
Write a program which draw a fractal of your choice following the documentation from here: http://natureofcode.com/book/chapter-8-fractals/.