-
Notifications
You must be signed in to change notification settings - Fork 0
/
Session5Assignment1.java
81 lines (72 loc) · 1.57 KB
/
Session5Assignment1.java
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
import java.util.Scanner;
abstract class Figure{
double dim1;
abstract void findArea();
abstract void findPerimeter();
}
class Circle extends Figure{
double area,perimeter;
Circle(double r)
{
dim1 = r;
area = 0;
perimeter = 0;
}
void findArea(){
area = 3.14*dim1*dim1;
System.out.println("Area of Circle : " + area);
}
void findPerimeter(){
perimeter = 2 * 3.14 * dim1;
System.out.println("perimeter of Circle : " + perimeter);
}
}
class Rectangle extends Figure{
double l,b,area,perimeter;
Rectangle(double l , double b)
{
this.l = l;
this.b = b;
area = 0;
perimeter = 0;
}
void findArea(){
area = l*b;
System.out.println("Area of Rectangle : " + area);
}
void findPerimeter(){
perimeter = 2 * (l + b);
System.out.println("perimeter of Rectangle : " + perimeter);
}
}
class Triangle extends Figure{
double b,h,area,perimeter;
Triangle(double b , double h)
{
this.h = h;
this.b = b;
area = 0;
perimeter = 0;
}
void findArea(){
area = 0.5*b*h;
System.out.println("Area of Triangle : " + area);
}
void findPerimeter(){
/*perimeter = 2 * (h + b);*/
System.out.println("perimeter of Triangle : Insufficient data to calculate perimeter" );
}
}
public class Session5Assignment1 {
public static void main(String s[]){
Circle c = new Circle(2);
Triangle t = new Triangle(2,3);
Rectangle r = new Rectangle(2,4);
c.findArea();
c.findPerimeter();
t.findArea();
t.findPerimeter();
r.findArea();
r.findPerimeter();
}
}