-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquare.java
More file actions
70 lines (57 loc) · 1.18 KB
/
Square.java
File metadata and controls
70 lines (57 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
66
67
68
69
70
public class Square implements Shapes
{
private double length;
public Square()
{
length = 0;
}
// initializes properties for shape if applicacle
public Square(double l) throws Exception
{
if(l > 0)
{
length = l;
}else{
throw new Exception("Data is not valid - tried to create Square");
}
}
// returns objects field and its perimeter
public String toString()
{
return "Square{l="+ length + "} " + getPerimeter();
}
//Calculates perimeter using length
public double getPerimeter()
{
Shapes Square = () ->{return 4*length;};
return Square.getPerimeter();
}
//Generates a unique value based up on objects parameters
public int hashCode()
{
int l = (int)Math.round(length)*3410/1424;
return l + 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 Square))
{
return false;
}
return length == ((Square)shape).getLength();
}
//gets length
public double getLength()
{
return length;
}
}