-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvgenyPobachienko.java
49 lines (42 loc) · 1.48 KB
/
EvgenyPobachienko.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.awt.geom.*;
import java.util.ArrayList;
import gpdraw.*;
public class EvgenyPobachienko implements Polygon{
private ArrayList <Point2D.Double> myPolygon = new ArrayList<Point2D.Double>();
public EvgenyPobachienko(){}
public void add(Point2D.Double aPoint){
this.myPolygon.add(aPoint);
}
public void draw(){
SketchPad sp = new SketchPad(300, 300);
DrawingTool pen = new DrawingTool(sp);
pen.move(this.myPolygon.get(0).getX(), myPolygon.get(0).getY());
pen.down();
for(int i = 0; i < this.myPolygon.size(); i++){
pen.move(this.myPolygon.get(i).getX(), myPolygon.get(i).getY());
}
pen.move(this.myPolygon.get(0).getX(), myPolygon.get(0).getY());
}
public double perimeter(){
double perim = 0.0;
for(int i = 0; i < this.myPolygon.size(); i++){
int j = i + 1;
if(j == this.myPolygon.size())j = 0;
perim += this.myPolygon.get(i).distance(this.myPolygon.get(j));
}
return perim;
}
public double area(){
double area = 0.0;
for(int i = 0; i < this.myPolygon.size(); i++){
int j = i + 1;
if(j == this.myPolygon.size()) j = 0;
area += this.myPolygon.get(i).getX()*this.myPolygon.get(j).getY() - this.myPolygon.get(i).getY()*this.myPolygon.get(j).getX();
}
if(area < 0) area = area*(-1);
return area/2;
}
public String getName(){
return "Evgeny Pobachienko";
}
}