-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircle.java
More file actions
65 lines (52 loc) · 1.18 KB
/
Circle.java
File metadata and controls
65 lines (52 loc) · 1.18 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
import java.lang.Math;
public class Circle implements Shapes
{
private double radius;
// initializes properties for shape if applicacle
public Circle(double d) throws Exception
{
if( d > 0)
{
radius = d;
}else{
throw new Exception("Data is not valid - tried to create Circle");
}
}
public Circle()
{
radius = 0;
}
// returns objects field and its perimeter
public String toString()
{
return "Circle{r=" + radius + "} " + getPerimeter();
}
//Calculates perimeter using radius
public double getPerimeter()
{
Shapes Circle = () ->{return Math.PI*2.0*radius;};
return Circle.getPerimeter();
}
//Generates a unique value based up on objects parameters
public int hashCode()
{
int r = (int)Math.round(radius)*3410/1424;
return r + 12;
}
// checks if its equal based on defined conditions and returns appropriate boolean
public boolean equals(Shapes shape)
{
if(this == shape)
return true;
if(shape == null)
return false;
if(!(shape instanceof Circle))
return false;
return radius == ((Circle)shape).getRadius();
}
//gets radius
public double getRadius()
{
return radius;
}
}