forked from natural/java2python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
98 lines (81 loc) · 2.76 KB
/
__init__.py
File metadata and controls
98 lines (81 loc) · 2.76 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# java2python -> top-level package marker.
public class RegularPolygon {
// Declare and initialize default values.
private int n = 3;
private double side = 1.0;
private double x = 0.0;
private double y = 0.0;
// Create constructor with default values.
public RegularPolygon(){
}
// Create constructor with new n and side values.
public RegularPolygon(int n, double side){
this.n = n;
this.side = side;
this.x = 0;
this.y = 0;
}
// Create constructor with new n, side, x, and y values.
public RegularPolygon(int n, double side, double x, double y){
this.n = n;
this.side = side;
this.x = x;
this.y = y;
}
// get n method
public int getN(){
return this.n;
}
// set n method.
public void setN(int n){
this.n = n;
}
// get side method.
public double getSide(){
return this.side;
}
// set side method.
public void setSide(double side){
this.side = side;
}
// get x-coordinate method.
public double getX(){
return this.x;
}
// set x-coordinate method.
public void setX(double x){
this.x = x;
}
// get y-coordinate method.
public double getY(){
return this.y;
}
// set y-coordinate method.
public void setY(double y){
this.y = y;
}
// Calculate Perimeter.
public double getPerimeter(){
return this.n * this.side;
}
// Calculate Area.
public double getArea(){
return (this.n * Math.pow(this.side,2)) / (4 * Math.tan(Math.PI/this.n));
}
// Pepresentation method of RegularPolygon object.
public String toString(){
String result;
if(this.n >= 3 && this.side > 0){
result = "The Regular Polygon n: " + this.n + ", side: "+ this.side + ", Area: " + this.getArea() + ", Perimeter: " + this.getPerimeter();
}else if(this.n >= 3 && this.side <= 0){
result = "The side length must be greater than zero.";
}else if(this.n < 3 && this.side > 0){
result = "The number of edges must be greater than three.";
}else{
result = "The side length must be greater than zero and the number of edges must be greater than three.";
}
return result;
}
} // End of RegularPolygon class.