forked from kajal200031/basic-python
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAbstractTriangle.java
More file actions
Latest commit
118 lines (84 loc) · 2.48 KB
/
Copy pathAbstractTriangle.java
File metadata and controls
118 lines (84 loc) · 2.48 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
importjava.util.Scanner;
publicabstractclassGeometricObject {
privateStringcolor = "white";
privatebooleanfilled;
protectedGeometricObject(Stringcolor, booleanfilled) {
this.color = color;
this.filled = filled;
}
publicStringgetColor() {
returncolor;
}
publicvoidsetColor(Stringcolor) {
this.color = color;
}
publicbooleanisFilled() {
returnfilled;
}
publicvoidsetFilled(booleanfilled) {
this.filled = filled;
}
voiddisplay()
{
System.out.println( "\ncolor: " + color + " and filled: " + filled);
}
publicabstractdoublegetArea();
publicabstractdoublegetPerimeter();
}
classTriangleextendsGeometricObject
{
doubleside1;
doubleside2;
doubleside3;
Triangle()
{
side1 = 1.0;
side2 = 1.0;
side3 = 1.0;
}
Triangle(doubleside1,doubleside2,doubleside3)
{
this.side1=side1;
this.side2=side2;
this.side3=side3;
}
Triangle(doubleside1,doubles2,doubleside3,Stringcolor,booleanfilled)
{
this(side1,side2,side3);//constructor chaining
setColor(color);
setFilled(filled);
}
publicvoidgetArea() //overriding abstract method
{
doubles = (side1 + side2 + side3) / 2;
doublea= Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));
System.out.println("Area="+a);
}
publicvoidgetPerimeter()//overriding abstract method
{
doublep= side1 + side2 + side3;
System.out.println("Perimeter="+p);
}
publicvoiddisplay()
{
System.out.println( "Triangle: side1 = " + side1 + " side2 = " + side2 +" side3 = " + side3);
super.display();
}
}
classPracticeProgram5
{
publicstaticvoidmain(String...s)
{
Scannerin=newScanner(System.in);
System.out.println("Enter the three sides of triangle");
doubleside1=input.nextDouble();
doubleside2=input.nextDouble();
doubleside3=input.nextDouble();
System.out.println("Enter the color");
Stringcolor=input.nextLine();
System.out.println("is triangle filled or not");
booleanfilled=input.nextBoolean();
Trianglet=newTriangle(side1,side2,side3,color,filled);
t.display();
}
}