-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTriangle.java
More file actions
58 lines (43 loc) · 1.27 KB
/
Triangle.java
File metadata and controls
58 lines (43 loc) · 1.27 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
// Computes Triangle
public class Triangle{
private int first_side;
private int second_side;
private int third_side;
private int height;
public Triangle(){
first_side = 0;
second_side = 0;
third_side = 0;
height = 0;
}
public Triangle (int first_side, int second_side, int third_side, int height){
this.first_side = first_side;
this.second_side = second_side;
this.third_side = third_side;
this.height = height;
}
public int computePerimeter(){
return first_side + second_side + third_side;
}
// Compute for Area
public int computeArea(){
return (third_side/2)*height;
}
public boolean isIscocelles(){
boolean flag = false;
if(first_side == second_side && second_side == third_side)
flag = true;
return flag;
}
public static void main (String[] args){
Triangle myTriangle = new Triangle(2, 4, 6, 8);
System.out.println(String.format("Triangle perimeter: %d", myTriangle.computePerimeter()));
// Compute for Triangle area
System.out.println(String.format("Triangle Area: %d", myTriangle.computeArea()));
// Checking Iscoscelles Condition
if(myTriangle.isIscoscelles())
System.out.println("It has equal side");
else
System.out.println("It has different side");
}
}