-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAreaofShape.java
68 lines (59 loc) · 1.55 KB
/
AreaofShape.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
import java.util.Scanner;
public class AreaofShape {
void computeArea(float a)
{
System.out.print("Area of square is "+a*a+"sq unit");
}
void computeArea(float l,float b)
{
System.out.print("Area of rectangle is "+l*b+"sq unit");
}
void computeArea(double r)
{
double area=3.14*r*r;
System.out.print("Area of circle is "+area+"sq unit");
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
AreaofShape as = new AreaofShape();
int choice = 1;
while(choice!=2)
{
System.out.print("\nSelect a choice"
+ "\n1.Rectangle"
+ "\n2.Square"
+ "\n3.Circle"
+ "\nEnter your choice:");
int option = sc.nextInt();
switch(option)
{
case 1:
System.out.print("Enter the length :");
float a =sc.nextFloat();
System.out.print("Enter the breadth :");
float b=sc.nextInt();
as.computeArea(a,b);
break;
case 2:
System.out.print("Enter the side : ");
float s =sc.nextFloat();
as.computeArea(s);
break;
case 3:
System.out.print("Enter the radius : ");
double ra =sc.nextDouble();
as.computeArea(ra);
break;
default:
System.out.println("Invalid choice");
}
System.out.print("\nDo you want to continue?"
+ "\n1:Yes"
+ "\n2:No");
System.out.println("\n");
System.out.println("Enter your choice:");
choice = sc.nextInt();
}
}
}