-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPerimeterDemo.java
56 lines (52 loc) · 1.08 KB
/
PerimeterDemo.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
import java .util .Scanner;
interface Perimeter
{
double PI=3.1415926;
double perimeter();
}
class Circle implements Perimeter
{
double radius;
public double perimeter()
{
return 2*PI*radius;
}
Circle()
{
this(0);
}
Circle(double d)
{
radius=d;
}
}
class Rectangle implements Perimeter
{
double length,breadth;
Rectangle()
{
this(0,0);
}
Rectangle(double a,double b)
{
length=a;
breadth=b;
}
public double perimeter()
{
return 2*length*breadth;
}
}
class PerimeterDemo
{
public static void main(String a[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter radius of circle : ");
Circle c=new Circle(sc.nextDouble());
System.out.println("Perimeter of circle is : "+c.perimeter());
System.out.print("Enter length and breadth of Rectangle : ");
Rectangle r=new Rectangle(sc.nextDouble(),sc.nextDouble());
System.out.println("Perimeter of Rectangle is : "+r.perimeter());
}
}