-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParallelogram.java
More file actions
74 lines (60 loc) · 1.44 KB
/
Parallelogram.java
File metadata and controls
74 lines (60 loc) · 1.44 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
public class Parallelogram implements Shapes
{
private double length;
private double height;
// initializes properties for shape if applicacle
public Parallelogram(double l,double h) throws Exception
{
if(l>0 && h > 0)
{
length = l;
height = h;
}else{
throw new Exception("Data is not valid - tried to create Parallelogram");
}
}
//calculates perimeter
public double getPerimeter()
{
Shapes Parallelogram = () ->{return 2*length + 2*height;};
return Parallelogram.getPerimeter();
}
// returns objects fields and its perimeter
public String toString()
{
return "Parallelogram{l=" + length + ", h="+ height + "} " + getPerimeter();
}
//getter methods
public double getLength()
{
return length;
}
public double getHeight()
{
return height;
}
//Generates a unique value based up on objects parameters
public int hashCode()
{
int l = (int)Math.round(length)*3410;
int h = (int)Math.round(height)*24110/4;
return l + h + 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 Parallelogram))
{
return false;
}
return length == ((Parallelogram)shape).getLength() && height == ((Parallelogram)shape).getHeight();
}
}