Feedback for these lessons is very much welcome. If you like or hate something about a lesson let us know, either on GitHub, via Mail or just tell us in person ;)
x
A04 - Class for Polygon and Point
We want to put the polygon and the euclidean distance exercise in own classes.1
Step 1
Create two classes one for the polygon (Polygon) and one for a point (Point2D). These two classes should be in seperate files.
But keep the Programm class with the main method.
Hint: All classes should be in the same namespace.
Step 2
The Point2D class needs the following members:
- fields for both coordinates
- two constructors - one for empty parameters and one for the coordinates as parameters
- one method to calculate the distance between two points
- the calculation is between the point itself and another point, given as a parameter
The Polygon class needs the following members:
- a
privatefield andpublicproperty for the array of vertices- if the vertices changed (per
set) it should recalculate the area
- if the vertices changed (per
- a property for the area
- with
getandprivate set
- with
- a property for the vertex count
- only a
get(it can get the count from the array)
- only a
- two constructors - one for epmty parameters and one for an array of points as parameter
- a
privatemethod that calculates the area of the polygon
Step 3
Update the calculation methods with the new datastructures.
Step 4 (Optional)
Put the whole process of the polygon creation in an own (static2) method in the Programm class.