-
Notifications
You must be signed in to change notification settings - Fork 0
/
Area.java
93 lines (93 loc) · 1.79 KB
/
Area.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
82
83
84
85
86
87
88
89
90
91
92
93
import java.util.Scanner;
abstract class Shape
{
int dim1,dim2;
Shape(int a ,int b)
{
dim1=a;
dim2=b;
}
Shape(int a)
{
dim1=a;
}
abstract double area();
}
class Rectangle extends Shape
{
Rectangle(int a, int b)
{
super(a,b);
}
double area()
{
return(double)(dim1*dim2);
}
}
class Triangle extends Shape
{
Triangle(int a, int b)
{
super(a,b);
}
double area()
{
return(double)(dim1*dim2*0.5);
}
}
class Circle extends Shape
{
Circle(int a)
{
super(a);
}
double area()
{
return(double)(3.14*dim1*dim1);
}
}
class Area
{
public static void main(String args[])
{
Scanner reader=new Scanner(System.in);
int choice,ch,a,b;
do
{
System.out.println("\t\t\tArea Calculation");
System.out.println("1.Rectangle\n2.Triangle\n3.Circle");
System.out.print("Enter your choice: ");
choice=reader.nextInt();
switch(choice)
{
case 1:
System.out.print("Enter the length: ");
a=reader.nextInt();
System.out.print("Enter the breadth: ");
b=reader.nextInt();
Rectangle r=new Rectangle(a,b);
System.out.println("The area of Rectangle is "+r.area());
break;
case 2:
System.out.print("Enter the base: ");
a=reader.nextInt();
System.out.print("Enter the height: ");
b=reader.nextInt();
Triangle t=new Triangle(a,b);
System.out.println("The area of Triangle is "+t.area());
break;
case 3:
System.out.print("Enter the radius: ");
a=reader.nextInt();
Circle c=new Circle(a);
System.out.println("The area of Circle is "+c.area());
break;
default:
System.out.println("Wrong Choice!!");
}
System.out.println("Do you want to continue: ");
ch=reader.nextInt();
}while(ch==1);
System.out.println("Thank you!!");
}
}