Assignment #2: Kaleidoscope


This time you learn how to write software cooperatively, the software development team is you and somebody who has written another part of the software (it might have been me, but that's unimportant as long as you don't want to sell the software). You have to create a class Triangle, which will be specified below. The class is part of a program, that takes the triangle and draws something. If you follow the specification, you will be rewarded by the output of this (or a similar) picture:


The big picture:

The software should create the image above, by producing different triangles, rotating and drawing them using different angles and colors. The part of rotating and drawing is already done. Your task is, to create a class that actually provides the triangle itself, which is not more than 3 vertices - well, it is a bit more:

The triangles need different sizes, and, since we are professional, the data structure containing the 3 points must be hidden. The API will tell you exactly what to do.


API of class Triangle

Fields: something that contains the 3 vertices. Since the class 'Kaleidoscope' will only use the data through the method 'getData', a further specification is not needed - it's up to you how to define the data.

Methods:


The class 'Kaleidoscope'

You don't need any knowledge about 'Kaleidoscope', except that:

Remarks

This assignment is about information hiding and the parameter 'this'. Please have that in mind. The information hiding here can be critical, e.g. if you define the vertices as a 2D array private int vertices[][] (of course private !), but then simply return a reference to vertices in the method 'getData()'. We will talk about that mistake in class.

The whole software design of the project is totally screwed up. A class calling another that again registers with the first one etc. - it's a mess for such a simple program. But it's a good example how to write one class just knowing the interface definition, and it was screwed up on purpose such that you have to use the 'this' parameter !


The code:

Class 1: Kaleidoscope.java
Class 2: Triangle.java (template)